Abdullah Shafique
Abdullah Shafique

Reputation: 6918

NSData to NSArray; Array empty

When I try to convert NSData to NSArray the array is empty. I know the data is not nil because I NSLogged it. Here is the code:

    NSData *arrayData = [NSData dataWithData:folderOpened.arrayOfItems];
    NSArray *array = [NSArray arrayWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:arrayData]];
    NSLog(@"%d",arrayData.length);
    NSLog(@"array count:%d",array.count);

My NSLog:

 285
 array count:0

My objects NSCoding protocols:

-(void)encodeWithCoder:(NSCoder *)aCoder
{

}
 -(id)initWithCoder:(NSCoder *)aDecoder
{ 
     return nil;
}

Upvotes: 1

Views: 1315

Answers (1)

mmackh
mmackh

Reputation: 3630

Make your custom objects NSCoding compliant to make them work with NSKeyedArchiver/Unarchiver. Here's a great starting point: http://nshipster.com/nscoding/

Upvotes: 2

Related Questions