# Swift4 KVC给类属性赋值报错

**URL:** <https://www.shiqidu.com/t/topic/588>\
**Category:** 开发调优\
**Tags:** Swift\
**Created:** [May 29, 2019, 6:51am UTC](https://www.shiqidu.com/t/topic/588 "2019-05-29T06:51:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
**Post date:** [May 29, 2019, 6:51am UTC](https://www.shiqidu.com/t/topic/588/1 "2019-05-29T06:51:13Z")

</div>

```swift
class Person : NSObject {
    var name : String?
    var age : Int = 0
    
    override init() {
        super .init()
    }
    
    init(dict : [String : Any]) {
        super.init()
        setValuesForKeys(dict)
    }
}

let p2 = Person(dict: ["name": "jakie", "age" : 61])
print(p2.name ?? "NoOne")
print(p2.age)

```

在使用kvc给类属性赋值时报了下面的错

```auto
error: Execution was interrupted, reason: signal SIGABRT. The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

```

解决这个错需要在属性前面加上`@objc`，如下

```swift
class Person : NSObject {
    @objc var name : String?
    @objc var age : Int = 0
    ...
}

```
