InitWithCoder: not visible in NSObject?

I have an interface:

#import <Foundation/Foundation.h> @interface Picture : NSObject; @property (readonly) NSString *filepath; - (UIImage *)image; @end 

and implementation:

 #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 

I get the error: Problem with ARC - No visible @interface for "NSObject" declares the selector "initWithCoder":

Is there anything else in NSCoding when using ARC? Thanks

+6
source share
1 answer

There is nothing else between ARC and manual reference counting. NSObject not NSCoding and therefore does not provide -initWithCoder: or -encodeWithCoder: Just don't skip to the superclass implementations of these methods.

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

Source: https://habr.com/ru/post/914410/


All Articles