2012-04-28 24 views
6

tengo una interfaz:initWithCoder: no visible en NSObject?

#import <Foundation/Foundation.h> 

@interface Picture : NSObject; 

@property (readonly) NSString *filepath; 
- (UIImage *)image; 

@end 

e implementación:

#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 

me sale error: tema ARC - No se @interface visibles para 'NSObject' declara el selector 'initWithCoder:'

¿Hay algo diferente acerca de NSCoding cuando se usa ARC? Gracias

Respuesta

13

No hay nada diferente entre ARC y el recuento manual de referencias. NSObject no se ajusta a NSCoding y, por lo tanto, no suministra -initWithCoder: o -encodeWithCoder:. Simplemente no llame a las implementaciones de superclase de esos métodos.

- (id)initWithCoder: (NSCoder *)aCoder { 
    self = [super init]; 
    if (self) { 
     [aCoder decodeObject: filepath forKey: kFilepath]; 
    } 
    return self; 
}