gpt4 book ai didi

ios - 接收 int 类型的集合元素不是 iOS 中的 objective-c 对象

转载 作者:IT王子 更新时间:2023-10-29 08:21:22 24 4
gpt4 key购买 nike

我有以下字典:

NSDictionary* jsonDict = @{
@"firstName": txtFirstName.text,
@"lastName": txtLastName.text,
@"email": txtEmailAddress.text,
@"password": txtPassword.text,
@"imageUrl": imageUrl,
@"facebookId": [fbId integerValue],
};

在最后一个元素中,我需要使用一个整数,但我收到错误:

collection element of type int is not an objective c object

如何在此元素中使用 int 值?

最佳答案

应该是:

@"facebookId": [NSNumber numberWithInt:[fbId intValue]];

NSDictionary 仅适用于对象,因此我们不能简单地存储 intintegerbool 或任何其他原始 数据类型。

[fbId integerValue] 返回原始整数值(不是对象)
因此,我们需要封装原始 数据类型并将它们制成对象。这就是为什么我们需要使用像 NSNumber 这样的类来创建一个对象来简单地存储这些废话。

更多阅读:http://rypress.com/tutorials/objective-c/data-types/nsnumber.html

关于ios - 接收 int 类型的集合元素不是 iOS 中的 objective-c 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20445335/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com