读取plist配置文件

配置文件如下:xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Student</key>
	<dict>
		<key>Name</key>
		<string>Yang</string>
		<key>Sex</key>
		<string>Male</string>
		<key>Num</key>
		<string>SX_010</string>
	</dict>
	<key>Mentor</key>
	<dict>
		<key>Name</key>
		<string>Gu</string>
		<key>Sex</key>
		<string>Male</string>
	</dict>
</dict>
</plist>

读取方式:

//首先读取studentInfo.plist中的数据
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"customInfo" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
    
//将学生信息填入视图
NSDictionary *tmpInfo = [dictionary objectForKey: @"Student"];
self.stuName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Name"]];
self.stuSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Sex"]];
self.stuNum.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Num"]];

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(plist)