如何检索文本字段文本并将其作为整数 32 存储在核心数据中?

Posted

技术标签:

【中文标题】如何检索文本字段文本并将其作为整数 32 存储在核心数据中?【英文标题】:How can I retrieve a textfields text and store it as an integer 32 in core data? 【发布时间】:2012-05-03 00:22:49 【问题描述】:

我正在尝试获取文本字段文本,将其转换为 int,并将其存储在核心数据整数 32 属性中。我在处理过程中遇到错误:

Implicit conversion of 'int' to 'NSNumber' disallowed  with arc

这是我尝试过的:

// trying to convert
int intLength = [self.length.text intValue];

// trying to set the current garden attribute to the converted int
self.currentGarden.length = intLength;

我该如何解决这个问题?

【问题讨论】:

【参考方案1】:

NSNumber 是一个对象,与 int 不同。尝试使用构造函数创建一个 NSNumber:

self.currentGarden.length = [NSNumber numberWithInt:intLength];

【讨论】:

以上是关于如何检索文本字段文本并将其作为整数 32 存储在核心数据中?的主要内容,如果未能解决你的问题,请参考以下文章