在的OBJ-C,常见的做法是使用的方便功能,执行常见的操作,如配置视图自动布局:结果调用[myFunction的]的未使用
func makeConstraint(withAnotherView : UIView) -> NSLayoutConstraint
{
// Make some constraint
// ...
// Return the created constraint
return NSLayoutConstraint()
}
如果你只需要设置约束和忘掉它,你可以拨打:
[view1 makeConstraint: view2]
如果你想存储的限制后,这样你可以删除/修改它,你会做这样的事情:
NSLayoutConstraint * c;
c = [view1 makeConstraint: view2]
我想这样做是迅速的,但如果我把上面的功能和不捕获返回的约束,我得到警告:
Result of call to 'makeConstraint(withAnotherView:)' is unused
很烦人。有什么方法让Swift知道我并不总是想捕获返回值?
注:我知道这一点。这是丑陋的,而不是什么我在寻找:
_ = view1.makeConstraint(withAnotherView: view2)
一方面你可以把@discardableResult一次并修复它们,但另一方面你不能与你的豆荚一起。所以你在函数调用前加上_ =来忽略结果 –