Write and Read a plist in swift with simple data

前端 未结 3 669
野性不改
野性不改 2020-12-15 14:38

i\'m trying to understand how to save a simple value, an integer, in a plist. but i\'m finding on the net only solution for save dictionary and array and i don\'t understand

3条回答
  •  死守一世寂寞
    2020-12-15 14:55

    You can't have anything other than an array or dictionary as the root object in a plist. This is because plist files are essentially special xml files so when you are trying to read the file you ask for object at key or object at index, otherwise you have no means of obtaining your data. Also, when inserting numbers into a plist, you must wrap them in the NSNumber class. To save your objects, check out this answer.

提交回复
热议问题