This was working and then it stopped.I've undone changes and it's still not working. And, I've got a very similar custom NSObject class that works fine. Here's the deal...
I have this custom class that will eventually be populated with data from a JSON object. Here's the .h file
#import <Foundation/Foundation.h>
@interface SKGreeting : NSObject <NSCoding>
@property (strong, nonatomic) NSNumber *gid;
@property (strong, nonatomic) NSString *sub;
@property (strong, nonatomic) NSString *mes;
@property (strong, nonatomic) NSString *usr;
@property (strong, nonatomic) NSDate *rec;
@property (strong, nonatomic) NSDate *sch1;
@property (strong, nonatomic) NSDate *sch2;
@property (strong, nonatomic) NSString *img; // name of the image
@property (strong, nonatomic) NSString *itp; // image type
@property (strong, nonatomic) NSNumber *typ;
@property (strong, nonatomic) UIImage *image; //actual image
@end
After I've received the JSON file, I run the following code to load it into the SKGreeting class. However, the SKGreeting object "greeting" is empty when it's added to the NSMutableArray greetings. So, the final result is some quantity of empty objects within "greetings".
+(NSMutableArray *)greetingsFromJSON:(NSData *)objectNotation error:(NSError **)error
{
NSError *localError = nil;
NSDictionary *parsedObject = [NSJSONSerialization JSONObjectWithData:objectNotation options:0 error:&localError];
if(localError != nil) {
*error = localError;
return nil;
}
NSMutableArray *greetings = [[NSMutableArray alloc] init];
// NSLog(@"Greetings: %@", greetings);
// NSLog(@"Parsed Object: %@", parsedObject);
NSArray *results = [parsedObject valueForKey:@"results"];
// NSLog(@"Results Record Count: %d", results.count);
// NSLog(@"array results: %@", results);
for (NSDictionary *greetDic in results)
{
SKGreeting *greeting = [[SKGreeting alloc] init];
for (NSString *key in greetDic)
{
if([greeting respondsToSelector:NSSelectorFromString(key)])
{
NSLog(@"%@ key: %@",key,[greetDic valueForKey:key]);
[greeting setValue:[greetDic valueForKey:key] forKey:key];
}
}
[greetings addObject:greeting];
}
// Save the data received to the user defaults
NSData *encodedGreetings = [NSKeyedArchiver archivedDataWithRootObject:greetings];
[[NSUserDefaults standardUserDefaults] setObject:encodedGreetings forKey:@"greetingsEncoded"];
return greetings;
}
As you can see, I've used several NSLog to make sure I'm getting content through the process, and I am. The setValue step doesn't add anything to the SKGreeting object. I can't figure out why the code isn't adding the data to "greeting". Help. Thanks.