Skip to content

Instantly share code, notes, and snippets.

@rentzsch
Created March 20, 2011 00:41
Show Gist options
  • Save rentzsch/877952 to your computer and use it in GitHub Desktop.
Save rentzsch/877952 to your computer and use it in GitHub Desktop.
@protocol ProtocolWithMethod
- (void)protocolMethod;
@end
@protocol ProtocolWithProperty
@property(retain) NSString *protocolProperty;
@end
// Trival base class that satisfies both protocols.
@interface BaseClass : NSObject {}
@property(retain) NSString *protocolProperty;
- (void)protocolMethod;
@end
@implementation BaseClass
@synthesize protocolProperty;
- (void)protocolMethod {}
@end
// Fine: compiler figures out ProtocolWithMethod's requirement for -protocolMethod was
// satisfied by BaseClass.
@interface SubClassImplementingProtocolWithMethod : BaseClass <ProtocolWithMethod> {}
@end
@implementation SubClassImplementingProtocolWithMethod
@end
// This class yields 2 warnings:
// 1. "property 'protocolProperty' requires method '-protocolProperty' to be defined - use
// @synthesize, @dynamic or provide a method implementation"
// 2. "property 'protocolProperty' requires the method 'setProtocolProperty:' to be
// defined - use @synthesize, @dynamic or provide a method implementation"
// The same warnings are issued across GCC 4.2, LLVM GCC 4.2 and clang 1.6, so I suppose
// this is Works As Intended.
@interface SubClassImplementingProtocolWithProperty : BaseClass <ProtocolWithProperty> {}
@end
@implementation SubClassImplementingProtocolWithProperty
@end
@thekarladam
Copy link

Sounds like rdar://6854729 again
Works fine in clang though.

//OCidentity.h
@interface OCIdentity
@Property (nonatomic, readonly, retain) NSString *rawID;
@EnD

//OCIdentityIM.h
@protocol OCIdentityIM
@EnD

//OCInstantMessage.h
//#import "OCIdentity.h"
//#import "OCIdentityIM.h"
@interface OCInstantMessage : NSObject {
OCIdentity *sender;
OCIdentity *recipient;
}
@EnD

@implementation OCInstantMessage

  • (NSString *)description {
    return [NSString stringWithFormat:@"%@", sender.rawID];
    }
    @EnD

Classes/OCInstantMessage.m: error: request for member 'rawID' in something not a structure or union

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment