“NSError”不支持作为RLMObject属性。所有属性都必须是基元

时间:2015-09-30 22:01:38

标签: swift2 xcode7 realm nserror

我的应用程序正在崩溃,并在控制台上将此错误返回给我。我的构建工作正常,但当我尝试运行单元测试时,我得到了这个。

  

'NSError'不支持作为RLMObject属性。所有属性必须是基元,NSString,NSDate,NSData,RLMArray或RLMObject的子类

这就是我的模型......

public class Place: Object {

// mongo id
public dynamic var _id: String = ""
// google id
public dynamic var google_id: String = ""
// name
public dynamic var name: String = ""
// score
public dynamic var score: Double = 0
// types
public let types = List<TypeObject>()
public dynamic var typeFormat: String = ""
// address
public dynamic var address: Address?
// geographic location
public dynamic var location: GeoJSON?
// phone
public dynamic var phone: Phone?
// open now
public dynamic var openNow: Bool = false
// hours
public let hours = List<Hours>()
// utc offset
public dynamic var utcOffset: Int = 0
// website
public dynamic var website: String = ""
// price level
public dynamic var priceLevel: Int = 0
// created at, updated at
public dynamic var createdAt: String = ""
public dynamic var updatedAt: String = ""
// visit
public let history = List<Visit>()
public dynamic var visitValue: VisitValue?
public dynamic var voteValue: VoteValue?
// reviews
public let reviews = List<Review>()
// photos
public let photos = List<Photo>()

...

模型类很大,所以省略了初始化器。需要注意的一点是,这个类不包含任何NSError类型,但包含函数,getter和setter,所有这些都不会引发任何类型的错误。我不知道这是否会影响模型,但他们在这一点上都做得很好。当我升级到Swift 2和XCode 7时,所有这些错误都开始发生了。我真的很难过,任何帮助都会很棒。

更新 我的问题是,在我优化代码的过程中,我在模型中的两个函数之间意外添加了var error: NSError?。我找不到它,因为我的模型充满了帮助函数,什么不是。所以我希望这可以帮助任何遇到这个问题的人只留下模型,并在模型本身之外放置任何与模式无关的代码。

1 个答案:

答案 0 :(得分:1)

Can you add an "Exception Breakpoint"? If so, you can then figure out which property in your model is causing the issue based off of the name variable passed into this method in RLMProperty.mm:

initSwiftPropertyWithName:indexed:property:instance:

which is ultimately calling setTypeFromRawType which is where the error is generated.

My guess is it is one of the object relationship properties because the error occurs when it is evaluating your model and checking if the property points to a subclass of Realm Object.