为什么 stringValue 在这里失败?
我正在尝试将数据从外部文件导入我的应用程序。一切正常,直到我添加 event.title (下面的第三个 objectAtIndex)。我认为我错误地使用了“stringValue”,它应该是其他东西。 floatValues 工作正常。
event.latitude = [[values objectAtIndex:0] floatValue];
event.longitude = [[values objectAtIndex:1] floatValue];
event.title = [[values objectAtIndex:2] stringValue];
这是头文件代码:
float latitude;
float longitude;
NSString *title;
}
@property (nonatomic) float latitude;
@property (nonatomic) float longitude;
@property (nonatomic, copy) NSString *title;
提前致谢。
I'm trying to bring data into my app from an external file. everything's working until I add the event.title (the 3rd objectAtIndex below). I think I'm incorrectly using "stringValue" and it should be something else. the floatValues work fine.
event.latitude = [[values objectAtIndex:0] floatValue];
event.longitude = [[values objectAtIndex:1] floatValue];
event.title = [[values objectAtIndex:2] stringValue];
here's the header file code:
float latitude;
float longitude;
NSString *title;
}
@property (nonatomic) float latitude;
@property (nonatomic) float longitude;
@property (nonatomic, copy) NSString *title;
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于字符串,您不需要获取 stringValue 或任何内容。 floatValue 用于 NSNumber,但您已经有一个普通的 NSString。
For strings, you don't need to get stringValue or anything. floatValue is for NSNumber, but you already have a plain NSString.
字符串如何存储在文件中,以及如何读取该文件?
我假设您可以删除
stringValue
方法并直接分配objectAtIndex:
的返回值 - 假设对象作为字符串读入。How is the string stored in the file, and how are you reading the file?
I would assume you can just drop the
stringValue
method and directly assign the return fromobjectAtIndex:
- assuming the object is read in as a string.