2012-04-23 2 views
1

plist에 부울 값을 쓰는 것에 대한 질문이 있습니다. 유선은 쓰기 전에 plist에 대한 dir이고 읽기는 완전히 동일하지만, 그 값에 부울 값을 쓸 수는 없습니다. 이 문제를 어떻게 해결할 수 있습니까? btw : iPhone 시뮬레이터에서 결과를 얻었지만 실제 iPhone 디버그에는 실패했습니다.plist에 boolean 파일 쓰기에 대해

//--- CODE HERE ---// 
[ContentList objectAtIndex: paramSender.tag] setValue: [NSNumber numberWithBool: TRUE] forKey: BooleanKey]; // set object boolean value to be ture; 
[ContentList writeToFile: self.plistPath atomically: YES]; // update the plist 
NSMutableArray *tmp = [[NSMutableArray alloc] initWithContentsOfFile: self.plistPath]; // get the content from the updated plist 
NSLog(@"the bool value is %@", [[ContentList objectAtIndex: paramSender.tag] objectForKey: BooleanKey]); 
NSLog(@"After update boolValue is %@", [[tmp objectAtIndex: paramSender.tag] objectForKey: BooleanKey]); 

//--- OUTPUT IN NSLOG ---// 
2012-04-23 18:09:12.164 iPhoneTips[151:707] the bool value is 1 
2012-04-23 18:09:12.167 iPhoneTips[151:707] After update boolValue is 0 

//--- FINISH ---// 

답변

0

대신이 시도 :

NSLog(@"After update boolValue is %d", [[[tmp objectAtIndex: paramSender.tag] objectForKey: BooleanKey] boolValue]); 
+0

아니요, 여전히 진짜 아이폰. – DavidBear

+0

왜 시뮬레이터와 실제 iPhone에서 결과가 다른지 궁금합니다. – DavidBear

0

이 봤어?

[[ContentList objectAtIndex: paramSender.tag] setBool:YES forKey: BooleanKey]; 
+0

. 나는 여기서 문제를 생각하지 않는다. contentlist는 객체의 부울 값을 변경할 수 있지만 원본 plist에는 쓸 수 없기 때문에 ...하지만 여전히 사전에 ~~~ – DavidBear

0

마지막으로, 나는 plist의 원리를 안다.

plist 번들은 읽기 전용입니다. 프로그래밍 방식으로 plist에 데이터를 쓰려면 plist 양식을 번들 문서 디렉토리로 이동 한 다음 쓰기 또는 읽기 작업없이 데이터를 편집해야합니다.

관련 문제