0

我有一个类(生成的核心数据):

@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 中的那些断点,并且调试表明它甚至没有调用它们!为什么?

4

1 回答 1

1

someMethod没有达到?NSLog检查是否在其头部使用断点或额外的。

如果不是,那么您的问题出在其他地方,因为您的程序流程与您预期的不同。

如果达到了,那么self.place显然是nil。这意味着您从未再次初始化它,您的程序流程与您想象的不同。

于 2012-04-18T17:32:54.413 回答