Xcode省略块的参数名称 [英] Xcode omitting parameters names of block

查看:30
本文介绍了Xcode省略块的参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的块属性:

I have a block property that looks like this:

@property (nonatomic, copy) void (^indexChangeBlock)(NSInteger index);

当我尝试设置此属性的值时,Xcode 自动完成功能将省略参数名称,结果如下所示:

When I try to set the value for this property, Xcode autocomplete will omit the parameter name leaving me with something like this:

[self.segmentedControl3 setIndexChangeBlock:^(NSInteger) {
    code
}];

然后 Xcode 显示一个 Parameter name missing 错误.我知道我可以通过手动添加参数名称来解决这个问题:

Then Xcode shows a Parameter name omitted error. I'm aware that I can solve this by adding the parameter name manually to make it look like this:

[self.segmentedControl3 setIndexChangeBlock:^(NSInteger index) {
    code
}];

我的问题是,如何让 Xcode 自动添加参数名称.或者换句话说,防止它删除它们.

My questions is, how can I make Xcode add the parameters names automatically. Or in other words, prevent it from removing them.

推荐答案

可能的解决方案:

typedef void (^IndexChangeBlock)(NSInteger index);

并使用

@property (nonatomic, copy) IndexChangeBlock indexChangeBlock;

如果你添加

- (void)setIndexChangeBlock:(IndexChangeBlock)indexChangeBlock;

一切正常

这篇关于Xcode省略块的参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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