【发布时间】:2012-04-30 02:58:36
【问题描述】:
我有一个类(生成核心数据):
@interface Place : NSManagedObject
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * subtitle;
@property (nonatomic, retain) NSNumber * latitude;
@property (nonatomic, retain) NSNumber * longitude;
@end
@implementation Place
@dynamic title;
@dynamic subtitle;
@dynamic latitude;
@dynamic longitude;
@end
为其添加一个类别:
@interface Place (Create)
+ (Place *)placeWithTitle:(NSString *)title
inManagedObjectContext:(NSManagedObjectContext *)context;
+(Place *) placeWithTitle:(NSString *)title andSubtitle:(NSString *)subtitle inManagedObjectContext:(NSManagedObjectContext *)context;
+(Place *) placeWithCoordinate:(CLLocationCoordinate2D) coordinate inManagedObjectContext:(NSManagedObjectContext *)context;
- (void) setLattitudeAndLongitudeByCoordinate:(CLLocationCoordinate2D) coordinate;
- (CLLocationCoordinate2D) coordinate;
@end
在这个类别中必须实例化方法:
- (void) setLattitudeAndLongitudeByCoordinate:(CLLocationCoordinate2D) coordinate
{
self.latitude=[NSNumber numberWithDouble:coordinate.latitude];//break point HERE
self.longitude=[NSNumber numberWithDouble:coordinate.longitude];
}
-(CLLocationCoordinate2D) coordinate
{
CLLocationCoordinate2D coord;//break point HERE
coord.latitude=[self.latitude doubleValue];
coord.longitude=[self.longitude doubleValue];
return coord;
}
如你所见,我必须在那里设置断点。现在,然后我调用这些方法
#import "Place+Create.h"
-(void)someMethod
{
[self.place setLattitudeAndLongitudeByCoordinate:coordiante];
}
它似乎永远不会到达方法 setLattitudeAndLogitudeByCoordinate 中的那些断点, 并且调试表明它甚至没有调用它们!为什么?
【问题讨论】:
-
有没有达到
someMethod?如果没有,那么您的问题出在其他地方。如果达到,那么self.place显然是nil。 -
是的,它解决了它。谢谢!
-
我在回答中重复这一点,以防止这个问题无人回答。
标签: objective-c ios xcode methods categories