Xcode 7,Obj-C,“Null传递给需要非空参数的被调用者” [英] Xcode 7, Obj-C, "Null passed to a callee that requires a non-null argument"

查看:169
本文介绍了Xcode 7,Obj-C,“Null传递给需要非空参数的被调用者”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  Null传递给要求非null参数的被调用者

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


$ $ b

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

我发现我应该使用 removeAllObjects

  [sectionTitles removeAllObjects]; 

但是,这不允许我评估 sectionTitles.count = = 0 。我尝试 sectionTitles == nil ,但是除非我使用 iniWithObjects 我不能以后添加对象。 p>

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

解决方案

为什么不尝试:

  sectionTitles = [[NSMutableArray alloc] init]; 

或以下任何一种:

  sectionTitles = [[NSMutableArray alloc] initWithCapacity:sectionTitles.count]; 
sectionTitles = [NSMutableArray new];
sectionTitles = [NSMutableArray array];
sectionTitles = [NSMutableArray arrayWithCapacity:sectionTitles.count];

可能是一些愚蠢的:

  sectionTitles = [NSMutableArray arrayWithArray:@ []]; 
sectionTitles = [@ [] mutableCopy];

有许多方法可以创建空的可变数组。只需阅读文档


In Xcode 7, I'm getting this warning:

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

.. from this nil initialization of a NSMutableArray...

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

I've found that I should be using removeAllObjects instead.

    [sectionTitles removeAllObjects];

However, this doesn't allow me to evaluate a sectionTitles.count == 0. I did try sectionTitles == nil, however unless I use iniWithObjects I can't add objects later on.

I need to set the array to nil or zero, when I refresh my datasource, when there's no records. I don't seem to be able to use addObject to add items unless I've used initWithObjects.

解决方案

Why don't you try:

sectionTitles = [[NSMutableArray alloc] init];

or any of the following:

sectionTitles = [[NSMutableArray alloc] initWithCapacity:sectionTitles.count];
sectionTitles = [NSMutableArray new];
sectionTitles = [NSMutableArray array];
sectionTitles = [NSMutableArray arrayWithCapacity:sectionTitles.count];

maybe some silly ones:

sectionTitles = [NSMutableArray arrayWithArray:@[]];
sectionTitles = [@[] mutableCopy];

There are lots of ways to create empty mutable arrays. Just read the doc.

这篇关于Xcode 7,Obj-C,“Null传递给需要非空参数的被调用者”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆