2011-02-16 7 views
2

필자가 수동으로 문서 폴더에 plist를 만들 때 plist에 배열을 쓰고 싶습니다.plist 파일 만들기

하지만 난 PLIST이 존재하는 경우 확인하지 않으면 것은 내가이 기록되는 Property List Programming Guide에로했다

..... 주요 번들 아무것도 일어나지에서 PLIST에서 그것을 만들 때.

NSString *plistRootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
NSString *plistPath = [plistRootPath stringByAppendingPathComponent:@"list.plist"]; 

if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) { 

    plistPath = [[NSBundle mainBundle] pathForResource:@"list" ofType:@"plist"]; 

} 

무엇을 놓쳤습니까?

편집 :

내가는 별도의 응용 프로그램에 기능을 tryed 그것은했다.

NString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
NSString *plistPath = [rootPath stringByAppendingPathComponent:@"list.plist"]; 

self.ListArray = [NSMutableArray arrayWithContentsOfFile:plistPath]; 
NSLog(@"preSave: %@", [ListArray count]); 
NSLog(@"%@", plistPath); 

및 로그는 말한다 : 그래서 다시 tryed

2011-02-16 16:54:56.832 ListApp[3496:207] .../Library/Application Support/iPhone Simulator/4.0.2/Applications/267F55E4-A46A-42E0-9E1C-EAF26846F75F/Documents/list.plist 

를하지만 디렉터리에 파일이 없습니다.!

+0

을 줄 수있는 방법 같은 놀라운되지 않습니다 당신의 정렬? array = [NSArray arrayWithContentsOfFile : plistPath]와 같은 것? – Vladimir

+0

시뮬레이터 또는 장치에서 테스트합니까? NSLog plistPath를 붙여 넣을 수 있습니까? –

+0

자세한 정보를 입력해야합니다. plistPath의 NSLog를 추가하고 출력을 게시 해보십시오. "list.plist"파일이 Xcode 프로젝트에 있습니까? –

답변

0

다른 Mac에서 코드를 tryed하고 작동합니다. 동일한 프로젝트입니다.

누군가 plist가 하나의 Mac에서는 만들어졌지만 다른 플레이어에서는 만들어지지 않은 이유를 설명 할 수 있습니까?

아이폰에는 plist도 쓰여 있지 않습니까? 나는 두 경우 모두 추측

이 내가 PLIST에 기록 배열이 비어 원인 :

NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
NSString *plistPath = [rootPath stringByAppendingPathComponent:@"list.plist"]; 
NSMutableArray *currentArray = [[NSMutableArray alloc] initWithContentsOfFile:plistPath]; 
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
      [selectet valueForKey:NAME], @"name", 
      nil]; 

NSLog(@" DIC. : %@", dictionary); 
[currentArray addObject:[dictionary copy]]; 
NSLog(@" %@", currentArray); 
[currentArray writeToFile:plistPath atomically:YES]; 
[currentArray release]; 

사전이 항목을 가지고 있지만 currentArray는 빈 .... 입니다 그리고 여전히 한 맥에서 작동 . 다른 쪽과 아이폰에는 없습니다.

편집 : 다시 일을 몇 가지 이유를 들어

.

문서 폴더에서 plist를 삭제하고 모든 대상을 삭제했는지 확인하십시오.

이제 문제는 이전과 같이 사전을 쓸 때만 쓸 수 있지만 그 다음에는 마지막으로 저장할 수 있습니다. 그리고 plist를 읽는 것도 효과가 없습니다.

아무도 말해 줄 수 있습니까? 왜 이런 일이 일어나고 어떻게 해결할 수 있습니까?

편집 2 : 나는 plist.When에 사전에 배열을 쓸 때 X-코드는 PLIST를 만들 수 없습니다 때문에 나는 X 있도록 PLIST에 사전을 썼다 :

내가 문제를 발견 -Code는 plist를 만들지 만 사전 Root를 사용하여 배열을 쓰지 않고 배열에서도 읽을 수 있습니다 .....

Array 폴더에 plist를 작성했습니다 그것을 문서 폴더에 존재하지 않을 때 그것을 복사하고 지금 ..... 작동한다

그것은 쉬운 일이 실제로 만들 경우 코드가없는 이러한 두통 당신에게

2
NSString *DocPath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 

filePath=[DocPath stringByAppendingPathComponent:@"AlarmClock.plist"]; 

if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) 
{ 
    NSString *path=[[NSBundle mainBundle] pathForResource:@"AlarmClock" ofType:@"plist"]; 
    NSLog(@"file path: %@",filePath); 
    NSDictionary *info=[NSDictionary dictionaryWithContentsOfFile:path]; 
    [info writeToFile:filePath atomically:YES]; 
} 

// * * *이 시도 ...