Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dova

macrumors newbie
Original poster
Oct 28, 2009
8
0
hello,

i would like to create a plist, then write and read <data></data> format for a key in the plist. The rest of keys are in string format.
The following code does what i want but it writes and reads all key in <string></string> instead of data format.
How can i get it to work?
Thanks!

write:
PHP:
/* write plist */
	NSString *plistPath = @"/Users/dova/Desktop/data.plist";
	NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] init];
	[plistDict setObject:info forKey:@"name"];
...
	[plistDict writeToFile:plistPath atomically:YES];

read:
PHP:
/* read plist */
	NSString *plistPath = @"/Users/dova/Desktop/data.plist";
	NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
	NSData *value;
	value = [plistDict objectForKey:@"name"];
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
What type of object is info? If it's a NSString then it'll get written as a string. You would need to convert (not cast) to NSData to get what you want.
 

dova

macrumors newbie
Original poster
Oct 28, 2009
8
0
The info is a string type (I got it to write and read it).
The next key is idata (setObject:idata forKey:mad:"data") in the string type, and i would like to convert it to data format for both read and write. but i do not know how.
 

dova

macrumors newbie
Original poster
Oct 28, 2009
8
0
i got it to encode in the data format:
PHP:
NSData * datax = [idata dataUsingEncoding:NSUTF8StringEncoding];
[plistDict setObject:datax forKey:@"data"];

how is it with decode to read? i do not found any info for decoding in the documentation.
Thank you
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
i got it to encode in the data format:
PHP:
NSData * datax = [idata dataUsingEncoding:NSUTF8StringEncoding];
[plistDict setObject:datax forKey:@"data"];

how it is with decode? i do not found any info for decoding in the documentation.
Thank you

Are you serious? On the same ***** page I linked to above is this, amazingly obviously named, clearly documented init method.

In all seriousness: if you couldn't see that give up now.
 

dova

macrumors newbie
Original poster
Oct 28, 2009
8
0
Thank you!
i got it to decode:
PHP:
NSData *datax = [idata dataUsingEncoding:NSUTF8StringEncoding];
NSString *dec_data = [[NSString alloc] initWithData:datax encoding:NSUTF8StringEncoding]; 
NSLog (@"decode: %@\n", dec_data);
 

dova

macrumors newbie
Original poster
Oct 28, 2009
8
0
I use the data format to store the encrypted key using openssl. The key is encrypted as plain text:
2f%¬•aÆe˝ídbG.oo]Ê!Ò?Ífi?√π–ùF?G—öYo¬@5Ä√ÏÈ;ä˝Á?è…ÁÉ?8ÉXê?ŒkÚO¡îT

Just to make sure that i won't have problem with some weird characters i need to convert it in the data format:
<data>
MmYlwqzigKJhw4Zly53DrWRiRy5vb13DiiHDkgTDje+sgRriiJrPgOKAk8O5RhxH4oCU
w7ZZb8KsQDXDhOKImsOPw4g7w6TLncOBHcOo4oCmw4HDiQU4w4lYw6ocxZJrw5pPwqHD
rlQATAfDkjx4bDfiiJrDt28Twq9vw6R64oC64omIw7jigJN64oCdw4QfDSrDtTA3B8ub
4oirw6fDssOVw7Q+wqNdZG9wFDx9a1Uzy4ZOw40oPWzCoMuGw4zCriHDiRJtxpLDqQ==
</data>
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Ah, OK, well that sounds sensible. I would check/ensure that the encoding you are choosing can represent all the characters you have though...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.