我有一个函数与此签名写在斯威夫特项目在Xcode 7.3.1:泛型参数“T”不能推断/不能明确专门的通用功能
func DLog<T>(@autoclosure object:() -> T, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
}
编译器抱怨Generic parameter 'T' could not be inferred
为这一呼吁:
DLog({ var text = "Returning output list\n"; for outline in outlines { text = text + outline.debugDescription + "\n"; }; return text; })
当我尝试提供种类它抱怨Cannot explicitly specialize a generic function
:
DLog<String>({ var text = "Returning output list\n"; for outline in outlines { text = text + outline.debugDescription + "\n"; }; return text; })
我已经尝试了更多的方法,但没有满足编译器。我也没有找到一个提示如何解决这个案件。
如何构建() => T
参数中的文本并将其正确传递给函数?
在Xcode 7.3.1中,我得到'不能用'(() - > String)类型的参数列表调用'DLog'。 – alik
这是因为当参数的类型具有'@ autoclosure'时你指定了一个闭包?你不能'@ autoclosure'关闭。 – BallpointBen
@alik尝试删除自动关闭属性 – Sweeper