开发者

Assignments using objectAtIndex

开发者 https://www.devze.com 2023-04-13 01:37 出处:网络
Why would this work: firstItem = @\"Some value\"; And this result in an error when I try to acces开发者_StackOverflow中文版s the NSString firstItem property:

Why would this work:

firstItem = @"Some value";

And this result in an error when I try to acces开发者_StackOverflow中文版s the NSString firstItem property:

NSArray *values = [dict allVaues];
firstItem = (NSString *)[values objectAtIndex:0];

From the .m:

@synthesize firstItem;

From the .h

NSString *firstItem;
@property (nonatomic, retain) IBOutlet NSString *firstItem;

NOTE: If I NSLog from the method I set this property it shows the correct values for the erring example, but later on the data is not available. I assume I need to set the values explicitly and not as references to my NSMutableDictionary that is out of scope. Any advice?


Your issue is you're not actually using the property. You're assigning the ivar directly instead. If you change your @synthesize line to say

@synthesize firstItem=_firstItem;

then you'll notice that your code using firstItem will no longer compile. That's a good sign that you're inadvertently ignoring the property accessors. You should be using self.firstItem = foo instead.

0

精彩评论

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

关注公众号