第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

無(wú)法在Swift中的另一個(gè)協(xié)議中使用協(xié)議作為關(guān)聯(lián)類型

無(wú)法在Swift中的另一個(gè)協(xié)議中使用協(xié)議作為關(guān)聯(lián)類型

一只斗牛犬 2019-08-28 15:42:37
無(wú)法在Swift中的另一個(gè)協(xié)議中使用協(xié)議作為關(guān)聯(lián)類型我有一個(gè)協(xié)議,Address它繼承自另一個(gè)協(xié)議Validator,并Address滿足Validator擴(kuò)展中的要求。還有另一個(gè)協(xié)議,F(xiàn)romRepresentable它有一個(gè)associatedType(ValueWrapper)要求Validator?,F(xiàn)在,如果我嘗試使用Addressas associatedType,那么它不會(huì)編譯。它說(shuō),推斷類型'Address'(通過(guò)匹配要求'valueForDetail')無(wú)效:不符合'Validator'。這種用法是非法的嗎?我們是不是應(yīng)該能夠使用Address的地方Validator,因?yàn)樗蠥ddresses都是Validator。下面是我正在嘗試的一段代碼。enum ValidationResult {     case Success     case Failure(String)}protocol Validator {     func validate() -> ValidationResult}//Address inherits Validatorprotocol Address: Validator {     var addressLine1: String {get set}     var city: String {get set}     var country: String {get set}}////Fulfill Validator protocol requirements in extensionextension Address {     func validate() -> ValidationResult {         if addressLine1.isEmpty {             return .Failure("Address can not be empty")         }         return .Success     }}protocol FormRepresentable {     associatedtype ValueWrapper: Validator     func valueForDetail(valueWrapper: ValueWrapper) -> String}// Shipping Address conforming to Address protocol.  // It should also implicitly conform to Validator since // Address inherits from Validator?struct ShippingAddress: Address {     var addressLine1 = "CA"     var city = "HYD"     var country = "India"}// While compiling, it says: // Inferred type 'Address' (by matching requirement 'valueForDetail') is invalid: does not conform // to 'Validator'. // But Address confroms to Validator.enum AddressFrom: Int, FormRepresentable {     case Address1     case City     case Country     func valueForDetail(valueWrapper: Address) -> String {         switch self {         case .Address1:             return valueWrapper.addressLine1         case .City:             return valueWrapper.city        case .Country:             return valueWrapper.country        }     }}更新:提起了一個(gè)錯(cuò)誤。
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 613 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)