0

这可能是一个 AppCode 问题,因为 Xcode 没有标记这个特定场景。

我在 AppCode 的各个地方都看到了这个错误:

Parameter type mismatch: Types 'nullable' and 'FooType' are not compatible

其中 FooType 可以是任何类型。

这是一个演示该问题的调用:

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:spinnerBackgroundView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];

toItem值被标记为警告的位置。

查看 API,toItem参数可以为空:

+(instancetype)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(nullable id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c;

这是由我调用 API 的方式引起的吗?或者它是 AppCode 中的一个小故障(除了“切换到 getter 模式”之外没有提供任何建议,这没什么区别。)

4

1 回答 1

0

几乎可以肯定这不是 AppCode 的错误,但是如果没有看到 FooType 的接口声明,就很难确定。这很可能是编译器将其解释为类型定义的错误放置的“可为空”属性。

于 2016-08-04T00:40:05.650 回答