0

this has been bugging me all morning, I have searched the hell out of this website and I can't find any reference to this issue.

Within my project I have 2 objects with circular dependancies set up exactly like this;

ClassA.h

@class ClassB;

@interface ClassA : NSObject {
    ClassB *foo;
}
@end

ClassA.m

#import "ClassB.h"

@implementation ClassA
    // Whatever goes here
@end

ClassB.h

@class ClassA;

@interface ClassB : NSObject {
    ClassA *foo;
}

@end

ClassB.m

#import "ClassA.h"

@implementation ClassB
    // Whatever goes here
@end

(CREDIT - Does Objective-C allow circular dependencies?)

This technique has been used by myself in several projects and up to now it was worked totally fine, each of the objects have been able to access each others properties perfectly.

A couple of days ago I added a few methods to ClassA and tried calling them from ClassB, again this worked totally fine..... so i thought, the problem is that I have been testing on iPhones with various OS versions on them but they have all been iPhone5S and above. Today I ran the project on the iPad2 simulator and it crashes when running SOME OF the methods, the same happens with iPhone4S and iPhone5 Simulators.

The methods I have in ClassA are just simple setters for example;

-(void)setHomeButtonPageContents:(NSString*)contents Index:(int)index
{
    homeButtonPageContents[index]=contents;
}

They are all variations of the above, some setting colours some setting fonts, but on the older devices (iPad2, iPhone4S & iPhone5) some work some don't.

Any Ideas?!?!

Community
  • 1
  • 1
  • What's the stack trace? Where does it crash? How is homeButtonPageContents defined? Do you have any qualifiers (weak, strong, etc.) or properties or instance variables? Is everything running on the same thread? You're not giving us much to work on... – jcaron Dec 02 '15 at 12:41
  • yes everything is running on the same tread. NSString *homeButtonPageContents[9]; - this is an instance variable defined in ClassA and the crash occurs when calling the method in the original thread from ClassA. this has been working fine on 64bit devices but anything lower won't work – Pretty Fly for a White Guy Dec 02 '15 at 14:13
  • `NSString *homeButtonPageContents[9]`? That's a very unusual pattern in Objective-C, and I'm honestly not sure it's actually correctly supported, especially with ARC. It also does not provide any range checking (and you're not checking it yourself either). Use an `NSMutableArray`. And check the value of your index, the actual bug may be somewhere else... – jcaron Dec 02 '15 at 18:47

1 Answers1

0

Are all the devices running the same version of the iOS? It could be that on these older devices you don't have the iOS version that can handle the methods you are calling.

mahboudz
  • 39,196
  • 16
  • 97
  • 124
  • Hi, Ive checked several different versions of iOS and it is definitely down to device type as opposed to OS. I have also tried all the different devices on the simulator and only iPad2, iPhone 4S and iPhone5 are effected. – Pretty Fly for a White Guy Dec 02 '15 at 12:31
  • There are other differences between device types. For example, older devices are not 64 bit. If you use an NSInteger on the newer devices, and then assume that on the older devices the NSInteger is the same size, then you will run into issues. The iPhone 5s is a 64 bit device. – mahboudz Dec 02 '15 at 12:34
  • I never knew that, thank you, that certainly gives me a new area to research. If i find anything useful I will post on here but as it stands my code is still goosed (for old devices anyway) :) – Pretty Fly for a White Guy Dec 02 '15 at 12:39
  • 1
    I ran into this in two situations: 1. I got index numbers from one device and would pass them to a UITableView on the other device. One device was 64bit and the other 32. I would assume that NSIntegers were 4 bytes and one or the other device would behave incorrectly because sometimes I needed to handle 8 bytes instead. 2. UIColor values for individual RGB are CGFloat which are different sizes under 32/64 bits. – mahboudz Dec 02 '15 at 12:45
  • I think you might be onto something there, the index I am passing over is a simple integers, I will do a little testing in a short while and let you know if you are correct, I have a feeling you are though!! – Pretty Fly for a White Guy Dec 02 '15 at 12:51