문제

내 앱에서 구현하는 설정에 PLIST를 사용할 수 있기를 원합니다. "디버그", "옵션 1", 옵션 2 "등과 같은 배열을 보유하기 위해 사전"설정 "이"설정 "사전 아래에서"디버그 "어레이에 어떻게 액세스 할 수 있습니까?

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *myPlistPath = [documentsDirectory stringByAppendingPathComponent:@"ProfileManager.plist"]; 
NSDictionary *plistDict = [[NSDictionary alloc] initWithContentsOfFile:myPlistPath]; 

swDebug.on = [plistDict objectForKey:@"Debug"];

.Plist

<?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>Current Profile</key>
<string>Sample Profile</string>
<key>Custom Profiles</key>
<array>
    <dict>
        <key>autolock</key>
        <false/>
        <key>bluetooth</key>
        <false/>
        <key>desc</key>
        <string>Example profile provided by the application</string>
        <key>edge</key>
        <false/>
        <key>phone</key>
        <false/>
        <key>push</key>
        <false/>
        <key>ringtone</key>
        <string>Example.m4r</string>
        <key>threeg</key>
        <false/>
        <key>title</key>
        <string>Example Profile</string>
        <key>vibrate</key>
        <false/>
        <key>wifi</key>
        <false/>
    </dict>
    <dict>
        <key>autolock</key>
        <false/>
        <key>bluetooth</key>
        <false/>
        <key>desc</key>
        <string>Sample profile provided by the application</string>
        <key>edge</key>
        <false/>
        <key>phone</key>
        <false/>
        <key>push</key>
        <false/>
        <key>ringtone</key>
        <string>Sample.m4r</string>
        <key>threeg</key>
        <false/>
        <key>title</key>
        <string>Sample Profile</string>
        <key>vibrate</key>
        <false/>
        <key>wifi</key>
        <false/>
    </dict>
</array>
<key>Settings</key>
<dict>
    <key>Debug</key>
    <string>ON</string>
</dict>
</dict>
</plist>
도움이 되었습니까?

해결책

예제 디버그는 배열이 아닌 문자열입니다 (이것은 질문에 있다고 말하는 것). 두 경우 모두 문제는 잘못된 DITT에서 키에 액세스하고 있다는 것입니다. 당신은 :

swDebug.on = [plistDict objectForKey:@"Debug"];

당신은 필요할 것입니다 :

swDebug.on = [[plistDict objectForKey:@"Settings"] objectForKey:@"Debug"];

설정은 사전 plist 내에서 사전이기 때문입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top