I\'ve got a very basic example where I\'m reading some data into a class from JSON, and my objects are getting corrupted somehow. I suspect I\'m missing some detail about how pr
This is not the root of yout problem but change your initWithJson:
to
-(id)initWithJson:(NSDictionary *)jsonObject
{
if(!(self = [super init] ) ) { return nil; }
_references = jsonObject[@"references"];
return self;
}
Ditch the custom setter and getter (you obviously don't need them).
In your case you can declare property simply with:
@property (strong) NSArray* references;
Change the NSArray * _references;
to:
@synthesize references = _references;
You can also omit the @synthesize
line in your case.
Also change _references = jsonObject[@"references"];
to:
_references = [NSArray arrayWithArray:jsonObject[@"references"]];
To sum it all together:
ANBNote.h
@interface ANBNote : NSObject
@property (strong) NSArray* references;
- (id)initWithJson:(NSDictionary*)data;
@end
ANBNote.m
#import "ANBNote.h"
@implementation ANBNote
-(id) init {
if(!(self=[super init])) return nil;
_references=@[];
return self;
}
-(id)initWithJson:(NSDictionary *)jsonObject {
if(!(self = [super init] ) ) { return nil; }
_references = [NSArray arrayWithArray:jsonObject[@"references"]];
return self;
}
@end