objective-c - 为什么我在 objective-c 中得到一个整数到指针的转换错误?

标签 objective-c ios

我正在遍历一个名为 previouslyDefinedNSString 的 NSString 对象,并验证代表字母 ASCII 值的整数是否在一个名为 mySetOfLettersASCIIValues 的 NSMutableSet 中,我之前已填充该对象使用 NSIntegers:

NSInteger ASCIIValueOfLetter;

    for (int i; i < [previouslyDefinedNSString length]; i++) {

        ASCIIValueOfLetter = [previouslyDefinedNSString characterAtIndex:i];

        // if character ASCII value is in set, perform some more actions...
        if ([mySetOfLettersASCIIValues member: ASCIIValueOfLetter])

但是,我在 IF 语句的条件下收到此错误。

Incompatible integer to pointer conversion sending 'NSInteger' (aka 'int') to parameter of type 'id';
Implicit conversion of 'NSInteger' (aka 'int') to 'id' is disallowed with ARC

这些错误是什么意思?我如何转换为对象类型(哪个 id 代表,对吗?)? NSInteger 不是对象吗?

最佳答案

你想让它成为一个 NSNumber,如:

NSInteger ASCIIValueOfLetter;

    for (int i; i < [previouslyDefinedNSString length]; i++) {

        ASCIIValueOfLetter = [previouslyDefinedNSString characterAtIndex:i];

        // if character ASCII value is in set, perform some more actions...
        if ([mySetOfLettersASCIIValues member: [NSNumber numberWithInteger: ASCIIValueOfLetter]])

现在您将获得所需的结果。

关于objective-c - 为什么我在 objective-c 中得到一个整数到指针的转换错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9961626/

相关文章:

iphone - YouTube API 广告支持 Objective-C?

ios - 如何更改导航栏标题的颜色?

ios - 使用 CoreBluetooth 是否可以获得蓝牙 LE 设备的原始扫描记录

ios - AFNetworking:getPath:参数方法导致问题

objective-c - Cocoa:回到之前的活跃应用?

ios - 如何从 URL 方案中获取参数。

html - ios webview css 和超链接在容器中的本地 html 文件中不起作用

ios - 尝试将框架 (Chameleon) 导入 Xcode (Swift) 时出现各种错误

android - 在 Android 和 iOS 上使用 QT 和 QML 编辑视频

objective-c - 为什么我对 NSLock 的使用不起作用?