开发者

How to correctly reference an object property in objective-c

I'm doing some cleanup after my Xcode 4 migration and noticed a few warnings that I can't get corrected. In the example below I'm trying to build an dynamic url to get an image.

NSString* imgUrl = [NSString stringWithFormat:@"http://images.localhost.com/Image/%@", [selectedHat img]];开发者_JAVA技巧

(selectedHat is an object with a @synth property "img" that is of type NSString)

The warning in Xcode is around how I get the img property from selectedHat

"method img not found (return type defaults to 'id')"

Obviously I'm not after a method (unless objective-c considers the getter on my property to be a method). This approach works fine, but I'm out to cleanup the warnings and understand how I should ask for the img property here going forward

Thank you in advance

Edit

The Hat interface looks something like the below

#import <Foundation/Foundation.h>

@interface Hat : NSObject {
  NSString* img;
}

@property (nonatomic, retain) NSString* img;

@end


You need to do two things. Not sure what your hat class is called, so lets call it Hat for this example:

  1. Make sure that the img property is declared in the Hat.h
  2. Make sure that you do #import "Hat.h" in any file calling this property.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜