앱이 할일 목록 앱과 매우 유사한 목록입니다. 그것은 괜찮지 만 영속 데이터 (NSUser Defaults)와 관련하여 코드를 추가 할 때 오류가 발생합니다. 아래에 오류 및 내 코드가 있습니다. (나는 NSUserdefaults 부분을 주석 처리했다.) 네가 나를 인도하고 해답을 줄 수 있기를 바랐다.영구 저장 오류 - 형식에 대한 속성 목록이 잘못되었습니다. 200
Error: 2015-01-19 22:26:40.783 Shoplisters[62316:22301266] Property list invalid for format: 200 (property lists cannot contain objects of type 'CFType') 2015-01-19 22:26:40.783 Shoplisters[62316:22301266] Attempt to set a non-property-list object ("", "") as an NSUserDefaults/CFPreferences value for key shoppingList 2015-01-19 22:26:40.785 Shoplisters[62316:22301266] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object ("", "") for key shoppingList'
코드 : 수입 UIKit
var shoppingList:[ShopList] = listData
class ShopListTableViewController: UITableViewController {
@IBAction func cancelToListView(segue:UIStoryboardSegue) {
dismissViewControllerAnimated(true, completion: nil)
//actions for cancel button
}
@IBAction func saveListDetail(segue:UIStoryboardSegue) {
let listDetailsViewController = segue.sourceViewController as AddNewListTableViewController
//add the new list to the shopping list array
shoppingList.append(listDetailsViewController.listDetails)
//NSUserdefaults
//let fixedShoppingList = shoppingList
//NSUserDefaults.standardUserDefaults().setObject(fixedShoppingList, forKey: "shoppingList")
//NSUserDefaults.standardUserDefaults().synchronize()
//update the table view
let indexPath = NSIndexPath(forRow: shoppingList.count-1, inSection: 0)
tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
//hide the detail view controller
dismissViewControllerAnimated(true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
//if NSUserDefaults.standardUserDefaults().objectForKey("shoppingList") != nil {
//shoppingList = NSUserDefaults.standardUserDefaults().objectForKey("shoppingList") as [ShopList]
//}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return shoppingList.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("listCell", forIndexPath: indexPath) as ShoppingListTableViewCell
//fill the prototype cell with the ff values:
var list = shoppingList[indexPath.row] as ShopList
cell.listNameLabel.text = list.name
cell.totalBudgetLabel.text = list.budget
cell.barColor.image = imageForColors(list.barColors)
return cell
}
데이터 : I 선언
let kString = "string"
let kInt = "int"
: 당신은 단순히 저장/다음과 같은 패턴으로 설정을 복원 할 수 있습니다
import Foundation
import UIKit
class ShopList: NSObject {
var name:String
var budget:String
var barColors:String
init(name:String, budget:String, barcolor:String) {
self.name = name
self.budget = budget
self.barColors = barcolor
super.init()
}
}
NSCoding을 준수하는 NSUserDefaults에만 요소를 넣을 수 있습니다. CFType은 그렇지 않습니다. 예를 들어 NSData 또는 이와 유사한 것. –
답장을 보내 주셔서 감사합니다. 사실 iOS에 신속하고 신속합니다. 기존 코드에 샘플을 제공 할 수 있습니까? 그것에 대해 어떻게 해야할지 잘 모릅니다. –