Your header Crap file should be
#import <Foundation/Foundation.h>
@interface Crap : NSObject <NSCoding>
@property (nonatomic, retain) NSArray *crapArray;
+ (Crap *) crap;
- (void)encodeWithCoder:(NSCoder *)enCoder;
- (id)initWithCoder:(NSCoder *)aDecoder;
@end
Your implementation Crap file should be
#import "Crap.h"
@implementation Crap
@synthesize crapArray;
+ (Crap *) crap {
static Crap *crap = nil;
if (!crap) {
crap = [[super allocWithZone:nil] init];
}
return crap;
}
+ (id) allocWithZone:(struct _NSZone *)zone {
return [self crap];
}
- (id) init {
self = [super init];
if (self) {
// set default property values
crapArray = nil;
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
//Encode properties, other class variables, etc
[encoder encodeObject:self.crapArray forKey:@"crapArray"];
}
- (id)initWithCoder:(NSCoder *)decoder {
if((self = [super init])) {
//decode properties, other class vars
self.crapArray = [decoder decodeObjectForKey:@"crapArray"];
}
return self;
}
@end
Then to set the value you got to do something like
[Crap crap].crapArray = [NSArray arrayWithObjects:@"Hello", @"Bye", nil];
And to get that value from another view controller you got to do something like
NSLog(@"Value: %d", [[Crap crap] crapArray].count);
If you do
Crap *crap = [[Crap alloc] init];
NSLog(@"%d", crap.crapArray.count);
crapArray will be set to nil and you are going to get 0 again, because we are setting crapArray to nil on the init method.