1
我獲得以下誤差的一個值:投擲方法不能是@objc協議中的一員,因爲它返回類型「布爾」
Throwing method cannot be a member of an @objc protocol because it returns a value of type 'Bool'; return 'Void' or a type that bridges to an Objective-C class
當定義夫特協議,還需要橋接到目標C :
@objc public protocol Saving {
func save() throws -> Bool
}
是否有其他的方式來定義它可以返回Bool
斯威夫特方法,可能會引發錯誤,並Objetive-C
兼容嗎?
爲什麼你想要返回一個Bool *和* throw?成功/失敗通過返回真/假或投擲來表示。 - ''func save()throws'將被轉換爲Objective-C爲' - (BOOL)saveAndReturnError:(NSError **)error;' –
「Swift with Cocoa and Objective-C」Swift function throwing錯誤將被轉換爲返回BOOL的Objective-C方法。 – Lukasz
我現在實際測試了它,並查看了Swift生成的頭文件,你是對的。 – Lukasz