OGeek|极客世界-中国程序员成长平台

标题: ios - initWithObjects :&value mean? 是什么意思 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 10:02
标题: ios - initWithObjects :&value mean? 是什么意思

Apple Document他们用 &value 初始化 NSSet 对象,我以前从未见过。有人可以为我解释一下吗?从文档中看,它似乎 initWithObjects: 需要 C 对象数组,&value 怎么变成数组?根据我的理解和使用来引用我在 &error 中看到的地址。

- (void)removeEmployeesObjectEmployee *)value
{
    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];

    [self willChangeValueForKey"employees"
          withSetMutation:NSKeyValueMinusSetMutation
          usingObjects:changedObjects];
    [[self primitiveEmployees] removeObject:value];
    [self didChangeValueForKey"employees"
          withSetMutation:NSKeyValueMinusSetMutation
          usingObjects:changedObjects];
}



Best Answer-推荐答案


在 C 中,数组基本上是指向地址的指针。这里的 &value 是一个指针,指向保存 (Employee *)value 的地址。您可以将其视为单值数组。如果有多个元素,则其他元素将在第一个元素之后彼此相邻保存。但是指针总是指向第一个元素。这就是为什么函数需要一个 count 参数来准确地知道要从第一个指针中提取多少值。

关于ios - initWithObjects :&value mean? 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27936412/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4