Hi,
I found have the following bit of code (iOS, Swift 3) that I got from an online tutorial but am having trouble making it work in swift 3. Any ideas what exactly needs changing?:
var notesArray:NSMutableArray!
var plistPath:String!
override func viewWillAppear(_ animated: Bool) {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
plistPath = appDelegate.plistPathInDocument
/
let data:NSData = NSFileManager.defaultManager().contentsAtPath(plistPath)!
do{
notesArray = try NSPropertyListSerialization.propertyListWithData(data, options: NSPropertyListMutabilityOptions.MutableContainersAndLeaves, format: nil) as! NSMutableArray
}catch{
print("Error occured while reading from the plist file")
}
self.tableView.reloadData()
}The plistPathInDocument is setup in app delegate and set to the path of the plist already. This method is essentially trying to populate a table view with data from a plist. Errors come from a few lines and suggests replacements making the code look like this:
var notesArray:NSMutableArray!
var plistPath:String!
override func viewWillAppear(_ animated: Bool) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
plistPath = appDelegate.plistPathInDocument
/
let data:NSData = FileManager.default.contents(atPath: plistPath)! as NSData
do{
notesArray = try PropertyListSerialization.propertyList(from: data as Data, options: PropertyListSerialization.MutabilityOptions.mutableContainersAndLeaves, format: nil) as! NSMutableArray
}catch{
print("Error occured while reading from the plist file")
}
self.tableView.reloadData()
}This gets rid of any errors prior to running it however once run in the simulator I get a "Thread 1: signal SIGABRT" error on line 11 after it crashes. Any ideas how to fix this would be appreciated.
Thanks
Owen