RealmSwift:xCode 9 上 属性 的无效值

RealmSwift: Invalid value for property on xCode 9

我在更新 Podfile 上的 Pod 版本时遇到错误。我在 xCode 9 上使用最新版本的 RealmSwift 框架。这是我的模型:

import Foundation
import RealmSwift
import ObjectMapper

class Salesman: Object,Mappable,DataElementDelegate, ObjectDelegate {

   //MARK: - properties
   public dynamic var id: Int = 0
   public dynamic var name: String = ""
   public dynamic var amount: Int = 0
   public dynamic var updated_at_timestamp: Int = 0

   //MARK: - Init
   required convenience init?(map: Map) {
       self.init()
   }

   //MARK: - Mapping
   func mapping(map: Map) {
       id<-map["id"]
       name<-map["name"]
       amount<-map["amount"]
       updated_at_timestamp<-map["updated_at_timestamp"]
   }

   //MARK: - Realm methods
   override static func primaryKey()->String?{
       return "id"
   }

   //MARK: - Methods
   public func getID()->Int{
       return self.id
   }

   //MARK: - Data delegate

   func getAmount() -> String {
       return "\(self.amount)"
   }

   func getName() -> String {
       return self.name
   }

   func getLastUpdate() -> Int {
       return self.updated_at_timestamp
   }

}

现在,当我尝试在我的领域中插入值时,我遇到了崩溃 'RLMException', reason: 'Invalid value '1000' for property 'Salesman.amount''

我写了插入代码:

//MARK: - Mocks Salesman
public func mocksSalesman()->[Salesman]{

    var array: [Salesman] = []

    let sale1 = Salesman()
    sale1.id = 1
    sale1.name = "Raul"
    sale1.amount = 1000

    let sale2 = Salesman()
    sale2.id = 2
    sale2.name = "Tomas"
    sale2.amount = 500

    let sale3 = Salesman()
    sale3.id = 3
    sale3.name = "Luciano"
    sale3.amount = 700

    array.append(sale1)
    array.append(sale2)
    array.append(sale3)

    return array

}

public func insert(){
    let list = self.mocksSalesman()
    let realm = try! Realm()
    for item in list{
        try! realm.write {
            realm.add(item, update: true)
        }
    }
}

我试图将 3 个推销员插入我的领域的数据库,但我遇到了这个问题。

会发生什么?

此致

好的,伙计们,我有答案了。那只是把这个代码:

func getAmount() -> Int {
   return self.amount
}

而不是:

func getAmount() -> String {
   return "\(self.amount)"
}