6
我有一個接口:initWithCoder:在NSObject中不可見?
#import <Foundation/Foundation.h>
@interface Picture : NSObject;
@property (readonly) NSString *filepath;
- (UIImage *)image;
@end
和實施:
#import "Picture.h"
#define kFilepath @"filepath"
@interface Picture() <NSCoding> {
NSString *filepath;
}
@end
@implementation Picture
@synthesize filepath;
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:filepath forKey:kFilepath];
}
- (UIImage *)image {
return [UIImage imageWithContentsOfFile:filepath];
}
@end
我得到錯誤:ARC問題 - 對 'NSObject的' 不可見@interface聲明選擇 '的initWithCoder:'
使用ARC時,NSCoding有什麼不同嗎? 謝謝