Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 28, 2009, 10:08 AM   #1
dova
macrumors newbie
 
Join Date: Oct 2009
Write/Read plist in <data> format

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 Code:
/* write plist */
    
NSString *plistPath = @"/Users/dova/Desktop/data.plist";
    
NSMutableDictionary *plistDict = [[NSMutableDictionary allocinit];
    [
plistDict setObject:info forKey:@"name"];
...
    [
plistDict writeToFile:plistPath atomically:YES]; 
read:
PHP Code:
/* read plist */
    
NSString *plistPath = @"/Users/dova/Desktop/data.plist";
    
NSMutableDictionaryplistDict = [[NSMutableDictionary allocinitWithContentsOfFile:plistPath];
    
NSData *value;
    
value = [plistDict objectForKey:@"name"]; 

Last edited by dova; Oct 28, 2009 at 10:19 AM.
dova is offline   0 Reply With Quote
Old Oct 28, 2009, 10:14 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
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.
robbieduncan is offline   0 Reply With Quote
Old Oct 28, 2009, 10:27 AM   #3
dova
Thread Starter
macrumors newbie
 
Join Date: Oct 2009
The info is a string type (I got it to write and read it).
The next key is idata (setObject:idata forKey:@"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 is offline   0 Reply With Quote
Old Oct 28, 2009, 10:32 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Read the documentation.
robbieduncan is offline   0 Reply With Quote
Old Oct 28, 2009, 10:58 AM   #5
dova
Thread Starter
macrumors newbie
 
Join Date: Oct 2009
i got it to encode in the data format:
PHP Code:
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
dova is offline   0 Reply With Quote
Old Oct 28, 2009, 11:00 AM   #6
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by dova View Post
i got it to encode in the data format:
PHP Code:
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.
robbieduncan is offline   0 Reply With Quote
Old Oct 28, 2009, 11:32 AM   #7
dova
Thread Starter
macrumors newbie
 
Join Date: Oct 2009
Thank you!
i got it to decode:
PHP Code:
NSData *datax = [idata dataUsingEncoding:NSUTF8StringEncoding];
NSString *dec_data = [[NSString allocinitWithData:datax encoding:NSUTF8StringEncoding]; 
NSLog (@"decode: %@\n"dec_data); 
dova is offline   0 Reply With Quote
Old Oct 28, 2009, 11:57 AM   #8
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
The real question is why? This is not really any more secure than just saving it as a string...
robbieduncan is offline   0 Reply With Quote
Old Oct 28, 2009, 12:32 PM   #9
dova
Thread Starter
macrumors newbie
 
Join Date: Oct 2009
I use the data format to store the encrypted key using openssl. The key is encrypted as plain text:
Quote:
2f%•ae˝dbG.oo]!?fi?√π–F?G—Yo@5√;˝?…?8X?ŒkOT
Just to make sure that i won't have problem with some weird characters i need to convert it in the data format:
Quote:
<data>
MmYlwqzigKJhw4Zly53DrWRiRy5vb13DiiHDkgTDje+sgRriiJrPgOKAk8O5RhxH4oCU
w7ZZb8KsQDXDhOKImsOPw4g7w6TLncOBHcOo4oCmw4HDiQU4w4lYw6ocxZJrw5pPwqHD
rlQATAfDkjx4bDfiiJrDt28Twq9vw6R64oC64omIw7jigJN64oCdw4QfDSrDtTA3B8ub
4oirw6fDssOVw7Q+wqNdZG9wFDx9a1Uzy4ZOw40oPWzCoMuGw4zCriHDiRJtxpLDqQ==
</data>
dova is offline   0 Reply With Quote
Old Oct 28, 2009, 03:34 PM   #10
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Ah, OK, well that sounds sensible. I would check/ensure that the encoding you are choosing can represent all the characters you have though...
robbieduncan is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: OS X Lion installed on partition - how to change read/write permissions JayS90 OS X 2 Oct 4, 2011 11:47 AM
problem with plist in tableview ghousemd iPhone/iPad Programming 0 Jul 6, 2011 05:26 AM
Reading and writing files and storage locations xcode portreathbeach iPhone/iPad Programming 1 Apr 2, 2011 06:22 PM
Reading and writing Windows and Linux file formats under Mac OS - what works? Mr.Bullitt Mac Basics and Help 3 Nov 26, 2009 08:53 AM
What format can a Mac write/read and a PC read? LSUtigers03 Mac Peripherals 4 Jun 16, 2009 10:09 AM


All times are GMT -5. The time now is 08:38 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC