我對Swift非常陌生,所以請耐心等待。我想使用ObjectMapper將我的Swift對象轉換爲JSON字符串。Swift,ObjectMapper:類型'User'不符合協議'Mappable'
我嘗試使用我的對象與Mappable接口,但我不斷收到此錯誤。
類型「ProductDTO」不符合協議「可映射」
我複製粘貼從git的文檔確切的代碼,但我得到了同樣的錯誤。 請幫忙,我在這花了3個小時。
import Foundation
import ObjectMapper
class User: Mappable {
var username: String?
var age: Int?
var weight: Double!
var array: [AnyObject]?
var dictionary: [String : AnyObject] = [:]
var bestFriend: User? // Nested User object
var friends: [User]? // Array of Users
var birthday: NSDate?
required init?(_ map: Map){
}
// Mappable
func mapping(map: Map) {
username <- map["username"]
age <- map["age"]
weight <- map["weight"]
array <- map["arr"]
dictionary <- map["dict"]
bestFriend <- map["best_friend"]
friends <- map["friends"]
birthday <- (map["birthday"], DateTransform())
}
}
Error: Type 'User' does not conform to protocol 'Mappable'
我完全不知道這可能是導致此。
我試着用Cocoapods,Carthage重新安裝ObjectMapper,最後把它作爲子模塊安裝,但沒有運氣。請幫忙!謝謝!
您正在使用哪個版本的ObjectMapper?這是最新的嗎? –
我正在使用的版本0.14 – dashbashrumble