我提高我的技能迅速,但我得到了這是我創建的數組的字典(NSArray中)與NSUserDefaults的給NSUserDefaults的NSArray的與錯誤的斯威夫特
錯誤。然後我想保存那本字典。
錯誤:
2014-11-22 11:50:29.222 __ Property list invalid for format: 200 (property lists cannot contain objects of type 'CFType') 2014-11-22 11:50:29.222 __ *** NSForwarding: warning: object 0x7fc6a3e03900 of class '__.Department' does not implement methodSignatureForSelector: -- trouble ahead Unrecognized selector -[__.Department isNSString__]
這些都是我的課:
請給我建議。我可能會因Array of Dictionary而失敗。
Department.swift
class Department {
var facultyMembers = [FacultyMember]()
let fullName: String
let shortName: String
init(fullName: String, shortName: String) {
self.fullName = fullName
self.shortName = shortName
}
func addMember(member: FacultyMember) {
facultyMembers.append(member)
}
}
University.swift
class University {
var departments:[[Department]]
init(){
departments = [[Department]]()
let userDefaults = NSUserDefaults.standardUserDefaults()
if let defaultItems = userDefaults.arrayForKey("departments"){
departments = defaultItems as [[Department]]
}else{
departments = [[Department]]()
userDefaults.setObject(departments, forKey: "departments")
}
}
func addDepartment(department: [Department]) {
departments.append(department)
let userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setObject(departments as NSArray, forKey: "departments")
}
}
如果我添加部門(其中包括一些教師),它給我的錯誤。
最好的問候。
它不工作。我會盡力解決這個問題。 – 2014-11-22 12:09:18