Skip to content

Instantly share code, notes, and snippets.

@ramiresnas
Created August 7, 2018 14:24
Show Gist options
  • Select an option

  • Save ramiresnas/ddc56e480c8b03291aec07ca2174b462 to your computer and use it in GitHub Desktop.

Select an option

Save ramiresnas/ddc56e480c8b03291aec07ca2174b462 to your computer and use it in GitHub Desktop.
create a property list
//MARK: PList
func createPList() {
let fm = FileManager.default
let docDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
guard let dir = docDirectory else {return}
let path = dir.appending("/example.plist")
if !fm.fileExists(atPath: path) {
let dict = [["name":"Ramires","age":24,"salary":798.89],["name":"Bia","age":18,"salary":798.89]] as NSArray
if dict.write(toFile: path, atomically: true) {
print("created on \(path)")
} else {
print("error to create \(docDirectory ?? "")")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment