How to Catch Invalid Type error during mapping of JSON Result to Realm object : <p>I have a realm Model like</p>

<pre><code>class User: Object {
    @objc dynamic var _id : String? = ""
    @objc dynamic var deviceCount = 0.0
    @objc dynamic var message : String?
    @objc dynamic var user_name : String?
    @objc dynamic var status : Bool = false
    @objc dynamic var phone_number : String = ""
    @objc dynamic var role : String?
    @objc dynamic var resCode = 0
    @objc dynamic var onlineTime = ""
    override static func primaryKey() -&gt; String? {
        return "_id"
    }
}
</code></pre>

<p>i am mapping json result to object model like this.</p>

<pre><code>let user = User(value: result as NSDictionary)
</code></pre>

<p>But app crashes if some variable have different type.
For example : If message variable is defined as String and in server response it is other than String then during mapping app will crash.
Is there any way to handle(Avoid crashes)</p>
