i know c passes by reference and im sure thats where my problem lies, but for the life of me i cannot figure this out. (also there may be a framework or a more proper way of doing this, which im open to suggestions)
CrestronControllerValues is just a getter and setter class
i intialize and pass it in my app delegate:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *keys = [NSArray arrayWithObjects:@"IPaddress", @"PortNumber", nil];
NSArray *objs = [NSArray arrayWithObjects:@"10.8.30.111", @"41794", nil];
NSDictionary *dict = [NSDictionary dictionaryWithObjects:objs forKeys:keys];
[defaults registerDefaults:dict];
CrestronControllerValues *CCV = [[[CrestronControllerValues alloc]init]autorelease];
[CCV setIPID:3];
[CCV setIPaddress:[defaults stringForKey:@"IPaddress"]];
[CCV setPortNumber:[defaults stringForKey:@"PortNumber"]];
cClient = [[CrestronClient alloc] initWithCCV:CCV];
as you can see the last line passes it to another class
this is where my problem comes into play
if i try to use getipaddress or getportnumber i get bad access
- (id)initWithCCV:(CrestronControllerValues *)ccv
{
[super init];
CCV = [CrestronControllerValues alloc];
CCV = ccv;
port = [[ccv getPortNumber] intValue];
ip = [ccv getIPaddress];
NSLog(@"ip %@ ~ port %@", ip, port);
return self;
}
i have tried multiple ways, including
cClient.ccv = ccv (as opposed to sending it with the init)
tried adding a getter for self so that it would be cClient = [[CrestronClient alloc] initWithCCV:[CCV getSelf]];
Considering
CCVin your last snippet of code is an ivar, try this instead:You don’t need to allocate space for an existing object. Also, be careful with your init method pattern, you may want to take a look in the documentation.