Creación de claves múltiples en matriz para plist
Frecuentes
Visto 102 equipos
0
I'm trying to enable image document types to an app using objc. I have root access to the plist
I need to write to. Just wrapping my head around how many keys, dictionaries, & arrays needed to code this has been frustrating me for over an hour. I can't get it right.
If I'm correct I'll need to create a NSMutableArray
en un parche de NSDictionary
en otro NSMutableArray
?
I'm using NSMutableDictionary to write to the plist as below:
NSMutableDictionary *data;
if ([fileManager fileExistsAtPath: path]) {
data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
} else {
//no plist
}
This is what I need to add to the plist:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Images</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.image</string>
</array>
</dict>
</array>
¿Alguien podría señalarme en la dirección correcta?
1 Respuestas
1
PList is the file representation of NSMutableDictionary :
Puede utilizar lo siguiente:
NSMutableDictionary *data;
if ([fileManager fileExistsAtPath: path]) {
data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
} else {
NSMutableArray *array = [[NSMutableArray alloc] init];
NSDictionary *dict = [[NSMutableDictionary alloc] init];
NSString *images = @"Images";
[dict setValue:images forKey:@"CFBundleTypeName"];
NSString *Alternate = @"Alternate";
[dict setValue:images forKey:@"LSHandlerRank"];
NSMutableArray *LSItemContentTypes = [[NSMutableArray alloc] init];
NSString *publicImage = @"public.image";
[LSItemContentTypes addObject:publicImage];
[dict setValue:LSItemContentTypes forKey:@"LSItemContentTypes"];
[data setObject:array forKey:@"CFBundleDocumentTypes"];
}
Respondido 12 Feb 14, 07:02
Thanks alot but you were missing one thing. You forgot to add: [array addObject:dict]; before the last line. Again, thanks alot. - Coca Cola
Ok...no prob..I want to give an idea only...enjoy - Samkit jainista
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas ios nsmutablearray nsdictionary or haz tu propia pregunta.
Are you trying to insert dict in array and then a array in dict ? - Samkit Jain