2011-04-13 2 views
7

정확히 .plist 파일은 무엇이며 어떻게 사용합니까? 내가 xcode에서 이것을 볼 때, 어떤 종류의 템플릿을 생성하는 것으로 보입니다. 내용을 배열로 밀어 plist 파일의 데이터를 추출 할 수있는 방법이 있습니까? 또한 .plist의 출처는 어디서 볼 수 있습니까?Plist : 사용법 및 사용 방법

답변

13

쉽게 다음 코드를 사용하여 배열에 PLIST의 내용을 얻을 수 있습니다 (다음 PLIST 배열했다 경우는 여기에 NSArray

형식 열거 것

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"plist"]; 
contentArray = [NSArray arrayWithContentsOfFile:filePath]; 

PLIST가 해당 단지 XML 파일입니다 : 우리는 여기에 Xcode 프로젝트의 일부)의 'file.plist'라는 파일을 여는 것 애플이 디자인 일부 DTD (데이터 형식 사전)는 DTD는 여기에서 볼 수있다 :

http://www.apple.com/DTDs/PropertyList-1.0.dtd

은 "객체"및 XML 파일에 포함 할 수있는 데이터 유형을 설명 things- 용 기타 DTD 단체 중에서 .

7

Plist는 속성 목록의 약자입니다. Apple에서 데이터를 저장하는 데 사용되는 파일 형식 일뿐입니다.

당신은 여기에 더 많은 정보를 얻을 수 있습니다 : http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man5/plist.5.html

당신은 속성 목록에서 읽고 싶은 경우

는 여기에서 확인 :

// Get the location of the plist 
// NSBundle represents the main application bundle (.app) so this is a shortcut 
// to avoid hardcoding paths 
// "Data" is the name of the plist 
NSString *path = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]; 

// NSData is just a buffer with the binary data 
NSData *plistData = [NSData dataWithContentsOfFile:path]; 

// Error object that will be populated if there was a parsing error 
NSString *error; 

// Property list format (see below) 
NSPropertyListFormat format; 

id plist; 

plist = [NSPropertyListSerialization propertyListFromData:plistData 
           mutabilityOption:NSPropertyListImmutable 
           format:&format 
           errorDescription:&error]; 

plist가 PLIST에서 최고 수준의 컨테이너가 어떤했다 될 수 있습니다. 예를 들어 plist가 사전 인 경우 plistNSDictionary이됩니다.

enum { 
    NSPropertyListOpenStepFormat = kCFPropertyListOpenStepFormat, 
    NSPropertyListXMLFormat_v1_0 = kCFPropertyListXMLFormat_v1_0, 
    NSPropertyListBinaryFormat_v1_0 = kCFPropertyListBinaryFormat_v1_0 
}; NSPropertyListFormat; 

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/PropertyLists/SerializePlist/SerializePlist.html.html

+1

코드를 보내 주셔서 감사합니다. 여기서 한 일을 한 줄씩 나에게 말할 수 있습니까? 또한 이러한 데이터 형식 중 일부는 (NSBundle, NSData, NSPropertyListFormat, NSPropertyListSerialization) 무엇인지 확실하지 않습니다. – locoboy

+0

@ cfarm54 내 게시물을 더 많은 인라인 코멘트로 업데이트했습니다. – AdamH