大家好,我是你的好朋友思创斯。今天说一说iphone plist_ios load和initialize,希望您对编程的造诣更进一步.


*plistpath = [[
nsbundle
mainbundle
]
pathforresource
:
@”test”
oftype
:
@”plist”
];
//
通过文件名
和
扩展名获取文件路径
*data = [[
nsmutabledictionary
alloc
]
init
];
//
读取路径文件中的信息
setobject
:
@”value_b”
forkey
:
@”key_b”
];
setobject
:
@”value_c”
forkey
:
@”key_c”
];
获取应用程序沙盒的
documents
目录
*paths =
nssearchpathfordirectoriesindomains
(
nsdocumentdirectory
,
nsuserdomainmask
,
yes
);
*plistpath1 = [paths
objectatindex
:
0
];
得到完整的文件名
*filename = [plistpath1
stringbyappendingpathcomponent
:
@”test123456.plist”
];
writetofile
:filename
atomically
:
yes
];
读取文件中的信息就可以判断是否文件操作成功
*data1 = [[
nsmutabledictionary
alloc
]
initwithcontentsoffile
:filename];
获取应用程序沙盒的
documents
目录
*plistpath1 = [paths
objectatindex
:
0
];
得到完整的文件名
*filename = [plistpath1
stringbyappendingpathcomponent
:
@”test123456.plist”
];
*data = [[
nsmutabledictionary
alloc
]
initwithcontentsoffile
:filename];
//
读取路径文件中的信息
设置属性值
,
没有的数据就新建,已有的数据就修改
objectforkey
:
@”users”
]
setobject
:
@”
逗比
“
forkey
:
@”name”
];
removeobjectforkey
:
@”key_c”
];
//
删除数据
setobject
:
@”cccccccccccc”
forkey
:
@”key_c”
];
//
测试时无法直接修改已存在
key
的值,可以先删除再添加方式来修改
writetofile
:filename
atomically
:
yes
];
读取文件中的信息就可以判断是否文件操作成功
*data1 = [[
nsmutabledictionary
alloc
]
initwithcontentsoffile
:filename];
文章由思创斯整理,转载请注明出处:https://ispacesoft.com/129878.html