创建完成的person类
@objc class Person: NSObject { @objc dynamic var name:String? init(name: String) { self.name = name; }
使用
var person:Person! self.person = Person.init(name: "xiaoming") print("name:\(person.name)")//name:Optional("xiaoming") // 取值 var value = self.person.value(forKey: "name") as? String //name:Optional("xiaoming") print("name:\(value)")//name:Optional("xiaoming") //使用 self.person.setValue("xiaohua", forKeyPath: "name") print("name:\(person.name)")//name:Optional("xiaohua") //使用字典 let dict = ["name":"小光"] self.person.setValuesForKeys(dict) let dictOut = self.person.dictionaryWithValues(forKeys: ["name"]) print("\(dictOut)")//["name": 小光]
原文地址:https://www.cnblogs.com/hualuoshuijia/p/11704733.html
时间: 2024-10-10 13:15:45