开发者

Setting an NSNumber property out of scope

开发者 https://www.devze.com 2023-01-10 01:34 出处:网络
For some or other reason when I call the init method and try and set the property it never seems to work:

For some or other reason when I call the init method and try and set the property it never seems to work:

//This is where I am setting the value
Hotel *newHotel = [[Hotel alloc]initWithCoordinate: coordinate 
                   hotelId:[NSNumber numberWithInt:1234]];


//This is the implementation of the method I am calling
- (id)initWithCoordinate:(CLLocationCoordinate2D)c hotelId:(NSNumber *)hId
{
   s开发者_C百科elf = [super init];
   coordinate = c;

   hotelId = hId; //When I access this property afterwards its always out of scope

   return self;
}

//This is the interface
@interface Hotel : NSObject <MKAnnotation>
{
  NSNumber *hotelId;
}

@property (nonatomic, retain) NSNumber *hotelId;

- (id)initWithCoordinate:(CLLocationCoordinate2D)c hotelId:(NSNumber *)hotelId;

@end


Use:

self.hotelId = hId;

so that you use the property's setter.


use

self.hotelId 

instead of hotelId... may be it is just showing out of scope... but the value has assigned properly


Your method descriptions in your interface and implementation don't match.


I changed the type to NSString in desperation and that worked. Please vote to close if you see fit but none of the suggestions worked.

0

精彩评论

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