gpt4 book ai didi

ios - Xcode 7,Obj-C, "Null passed to a callee that requires a non-null argument"

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

在 Xcode 7 中,我收到此警告:

Null passed to a callee that requires a non-null argument

.. 从这个 NSMutableArray 的 nil 初始化...

    sectionTitles = [[NSMutableArray alloc] initWithObjects:nil];

我发现我应该改用 removeAllObjects

    [sectionTitles removeAllObjects];

但是,这不允许我计算 sectionTitles.count == 0。我确实尝试了 sectionTitles == nil,但是除非我使用 iniWithObjects,否则我以后无法添加对象。

当我刷新我的数据源时,当没有记录时,我需要将数组设置为零或零。我似乎无法使用 addObject 添加项目,除非我使用了 initWithObjects

最佳答案

传递非空参数只是部分答案。

The new Objective-C nullability annotations have huge benefits for code on the Swift side of the fence, but there's a substantial gain here even without writing a line of Swift. Pointers marked as nonnull will now give a hint during autocomplete and yield a warning if sent nil instead of a proper pointer.

阅读 NSHipster comprehensive article .

为了在您自己的代码中利用相同的契约(Contract),请使用 nonnullnullable:

Obj-C

- (nullable Photo *)photoForLocation:(nonnull Location *)location

关于ios - Xcode 7,Obj-C, "Null passed to a callee that requires a non-null argument",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31088137/

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