【问题标题】:Is there any isMember kind of method for Objective-C int array?Objective-C int 数组是否有任何 isMember 类型的方法?
【发布时间】:2016-08-17 07:53:34
【问题描述】:

Objective-C int 数组有没有 isMember 类的方法?

我的意思是,无论myMethod的参数是在myArray中还是在myArray中,我怎样才能得到一个BOOL值?

@implementation myController

int counter;
int *myArray[10] = {2,3,9,10,11,15,16,17,18,25};

- (id) init {


    if (self = [super init]) {

    }
    return self;

}

- (void)myMethod:x:(int)x
{
    if (myArray.isMember(x) ) {
        <#statements#>
    }
    else {
        <#some other statements#>
    }
}

【问题讨论】:

  • myArray 不是 Objective-C 数组,而是 C 数组。
  • 顺便说一下,数组存储int *,可能不是你想要的。
  • 您实际上并不需要像*myArray[10] 这样的指向数组指针的指针,对吗?顺便说一句,你为什么不改用NSArray&lt;NSNumber&gt; *NSArray 有大量高级方法可以帮助您处理元素;请参阅 docs
  • 我知道 NSArray。我只是在玩弄 Objective-C。 int * 正是我想要的。不过还是谢谢你的回复。。

标签: ios objective-c arrays nsarray


【解决方案1】:

这样

NSArray * array = @[@1, @2, @3, @4];
if ([array containsObject:@1]) // will return true
if ([array containsObject:@5]) // will return false

【讨论】:

    猜你喜欢
    • 2013-10-17
    • 2013-05-29
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    相关资源
    最近更新 更多