开发者

Whats wrong with this protocol declaration?

I am doing this as learning and I have been told that NSString return type type is not right.

Is it that the type should be (NSString*)not(NSString)

@protocol MyExampleProtocol <NSObject>

@required
@property (nonatomic,retain) NSString *model;
@property (nonatomic,retain) NSString *resgisteration;
-(NSString) getModelAndRegistration();
@optional
@pro开发者_Go百科perty (nonatomic,retain) NSString *engine;
@property (nonatomic,retain) NSString *chasis;
-(NSString) getEngineAndChasis();
@end


Yes, you need to return a pointer to the NSString object since NSString is not a primitive type. Therefore you need to use

- (NSString *) getEngineAndChasis;  

Also, drop the parentheses, these are not used in Objective-C


Is it that the type should be (NSString*)not(NSString)

Yes, the return type should be NSString*. In Objective-C, every thing is a reference except the primitive data types like int, float etc., Also member functions don't have a ending (), as in C++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜