initWithCoder: not visible in NSObject?

cocoa-touch, ios, nscoding, objective-c

Solution

There's nothing different between ARC and manual reference counting. `NSObject` doesn't conform to `NSCoding` and therefore doesn't supply `-initWithCoder:` or `-encodeWithCoder:`. Just don't call through to the superclass implementations of those methods.

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

Problem

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 error: ARC issue - No visible @interface for 'NSObject' declares the selector' initWithCoder:' Is there something different about NSCoding when using ARC? Thanks

Original source