У меня все еще есть проблемы с NSKeyedArchiver.
Я реализовал все, что мне сказали, но все равно не работает. Я немного расстроен. Так кто-нибудь может мне помочь?
Вот файл .h:
#import <Foundation/Foundation.h>
#import "JFIdentifier.h" // This is my own class to create a unique identifier for every JKDataObject
@interface JKDataObject : NSObject <NSCoding> {
NSUInteger identifier;
NSString *user;
NSDate *creationDate;
NSDate *alteredDate;
}
#pragma mark -
#pragma mark Setter
- (void)setIdentifier:(NSUInteger)newIdentifier silent:(BOOL)silent;
- (void)setUser:(NSString *)newUser silent:(BOOL)silent;
- (void)setCreationDate:(NSDate *)newCreationDate silent:(BOOL)silent;
- (void)setAlteredDate:(NSDate *)newAlteredDate;
#pragma mark -
#pragma mark Getter
- (NSUInteger)identifier;
- (NSString *)user;
- (NSDate *)creationDate;
- (NSDate *)alteredDate;
#pragma mark -
#pragma mark Methods
- (void)dataObjectWasAltered:(JKDataObject *)alteredObject;
#pragma mark -
@end
и это файл .m:
#import "JKDataObject.h"
@implementation JKDataObject
#pragma mark -
#pragma mark Initiation
- (id)init {
[super init];
identifier = [JFIdentifier createIdentifier];
user = [[NSString alloc] initWithString:NSUserName()];
creationDate = [[NSDate alloc] initWithTimeIntervalSinceNow:0];
alteredDate = [[NSDate alloc] initWithTimeIntervalSinceNow:0];;
return self;
}
- (id)initWithCoder:(NSCoder *)decoder {
[super init];
identifier = [decoder decodeIntegerForKey:@"identifier"];
user = [[decoder decodeObjectForKey:@"user"] retain];
creationDate = [[decoder decodeObjectForKey:@"creationDate"] retain];
alteredDate = [[decoder decodeObjectForKey:@"alteredDate"] retain];
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
// [super encodeWithCoder:encoder];
[encoder encodeInteger:identifier forKey:@"identifier"];
[encoder encodeObject:user forKey:@"user"];
[encoder encodeObject:creationDate forKey:@"creationDate"];
[encoder encodeObject:alteredDate forKey:@"alteredDate"];
}
- (void)release {
[user release];
[creationDate release];
[alteredDate release];
[super release];
}
#pragma mark -
#pragma mark Setter
- (void)setIdentifier:(NSUInteger)newIdentifier silent:(BOOL)silent {
identifier = newIdentifier;
if (!silent) {
[self dataObjectWasAltered:self];
}
}
- (void)setUser:(NSString *)newUser silent:(BOOL)silent {
user = newUser;
if (!silent) {
[self dataObjectWasAltered:self];
}
}
- (void)setCreationDate:(NSDate *)newCreationDate silent:(BOOL)silent {
creationDate = newCreationDate;
if (!silent) {
[self dataObjectWasAltered:self];
}
}
- (void)setAlteredDate:(NSDate *)newAlteredDate {
alteredDate = newAlteredDate;
}
#pragma mark -
#pragma mark Getter
- (NSUInteger)identifier {
return identifier;
}
- (NSString *)user {
return user;
}
- (NSDate *)creationDate {
return creationDate;
}
- (NSDate *)alteredDate {
return alteredDate;
}
#pragma mark -
#pragma mark Methods
- (void)dataObjectWasAltered:(JKDataObject *)alteredObject {
alteredDate = [[NSDate alloc] initWithTimeIntervalSinceNow:0];
}
#pragma mark -
@end
Кто-нибудь знает, что я сделал не так?
Спасибо !!