0

我是IOS开发的新手。我有包含以下内容的课程。细节:

@interface GeoFenceReferenceDetails : NSObject {
    NSString* directionType;
    NSString* fenceCode;
    NSNumber* fenceId;
    NSString* fenceName;
    NSString* geoFenceType;
}

另一个用于创建字典的“实用程序”类:

-(NSDictionary *) createGeoReferenceDict2: (GeoFenceReferenceDetails *) geoFenceDetails {    
return [NSDictionary dictionaryWithObjectsAndKeys:
        geoFenceDetails.directionType, @"directionType",
        geoFenceDetails.fenceCode, @"fenceCode",
        geoFenceDetails.fenceId, @"fenceId",
        geoFenceDetails.fenceName, @"fenceName",
        geoFenceDetails.geoFenceType, @"geoFenceType",
        nil];
}

现在我想在第三个类中创建一个 GeoFenceReferenceDetails 对象,它以下列方式提供输出:

{
directionType = None;
fenceCode = 12;
fenceId = 81;
fenceName = "ABC";
geoFenceType = Circle;
}

这就是我正在做的事情。我在第三类中创建 GeoFenceReferenceDetails 的“fenceDetails”对象,然后执行以下操作:

 fenceDetails = [[GeoFenceReferenceDetails alloc] init];

fenceDetails.fenceId=[NSNumber numberWithInt:121];
 NSLog(@"%i",[fenceDetails.fenceId intValue]);
  NSDictionary* geoFenceReference = [[Utility sharedInstance] createGeoReferenceDict2:fenceDetails];

NSLog(@"%@ ",[geoFenceReference description]);

但我得到的只是

{

}

你能帮助我吗 ?

4

2 回答 2

0

这意味着您的字典对象未分配或不包含任何值。

您需要检查的事项很少。

  1. 检查是否sharedInstance分配Utility对象。
  2. 还要确保它的字典对象geoFenceReference不为零。
  3. 放置断点调试代码。
于 2012-09-24T06:03:56.583 回答
0

将此添加到您的 .h 接口类声明中:

@interface GeoFenceReferenceDetails : NSObject {
    NSString* directionType;
    NSString* fenceCode;
    NSNumber* fenceId;
    NSString* fenceName;
    NSString* geoFenceType;
}
@property (nonatomic, retain) NSString *directionType;
@property (nonatomic, retain) NSString *fenceCode;
@property (nonatomic, retain) NSString *fenceId;
@property (nonatomic, retain) NSString *fenceName;
@property (nonatomic, retain) NSString *geoFenceType;

这到你的 .m 实现文件

@synthesize directionType, fenceCode, fenceId, fenceName, geoFenceType;

- (void)dealloc {
    self.directionType = nil;
    self.fenceCode = nil;
    self.fenceId = nil;
    self.fenceName = nil;
    self.geoFenceType = nil;
    [super dealloc];
}

- (NSString *)description {
return [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@", self, self.directionType, self.fenceCode, self.fenceId, self.fenceName, self.geoFenceType];
}

在没有 IDE 的情况下写了这个,所以我为拼写错误道歉,如果有的话。希望这可以帮助。

于 2012-09-24T06:22:42.033 回答