菜鸟教程小白 发表于 2022-12-13 10:02:50

ios - initWithObjects :&value mean? 是什么意思


                                            <p><p>在 <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html" rel="noreferrer noopener nofollow">Apple Document</a>他们用 &value 初始化 NSSet 对象,我以前从未见过。有人可以为我解释一下吗?从文档中看,它似乎 <code>initWithObjects:</code> 需要 C 对象数组,&value 怎么变成数组?根据我的理解和使用来引用我在 &error 中看到的地址。</p>

<pre><code>- (void)removeEmployeesObject:(Employee *)value
{
    NSSet *changedObjects = [ initWithObjects:&amp;value count:1];

    [self willChangeValueForKey:@&#34;employees&#34;
          withSetMutation:NSKeyValueMinusSetMutation
          usingObjects:changedObjects];
    [ removeObject:value];
    [self didChangeValueForKey:@&#34;employees&#34;
          withSetMutation:NSKeyValueMinusSetMutation
          usingObjects:changedObjects];
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在 C 中,数组基本上是指向地址的指针。这里的 <code>&value</code> 是一个指针,指向保存 <code>(Employee *)value</code> 的地址。您可以将其视为单值数组。如果有多个元素,则其他元素将在第一个元素之后彼此相邻保存。但是指针总是指向第一个元素。这就是为什么函数需要一个 <code>count</code> 参数来准确地知道要从第一个指针中提取多少值。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - initWithObjects :&amp;value mean? 是什么意思,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/27936412/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/27936412/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - initWithObjects :&amp;value mean? 是什么意思