I have an array, and I want to store that array into a plist file. How can I do this?
Asked
Active
Viewed 2,909 times
3 Answers
3
Assuming that you have a variable urArray
holding the array and an NSString
variable called pListFilePath
that holds the complete path name of the file you want to create, then this will do it:
[urArray writeToFile:pListFilePath atomically:YES];
-
@7KV7: thanks.. i have an NSDictionary how can i store this array into that NSDictionary... – user701630 May 04 '11 at 05:27
-
I think you can initialize the dictionary from the plist file that you just created – visakh7 May 04 '11 at 05:30
-
`NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:filePath]; ` – visakh7 May 04 '11 at 05:31
-
@7KV7:I have initilized the NSDicitionary but how can i save that array into the NSDicitionary... – user701630 May 04 '11 at 06:20
-
You transferred the array to the plist file and then u read from the file to dictionary so you have the array in the dictionary..... – visakh7 May 04 '11 at 06:21
-
Apple recommends using URLs instead of file paths. – May 04 '11 at 06:31
2
Follow this steps:for NSArray
store into plist
Example : arrResult
is your array
NSMutableDictionary *dict1=[[NSMutableDictionary alloc]init];
[dict1 setValue:arrResult forKey:@"Result"];
[dict1 writeToFile:[self plistPath] atomically:YES];
[dict1 release];
1
NSMutableDictionary *dict1=[[NSMutableDictionary alloc]init];
[dict1 setValue:txtUserName.text forKey:@"username"];
[dict1 setValue:txtPassword.text forKey:@"password"];
[dict1 writeToFile:[self plistPath] atomically:YES];
[dict1 release];

NSResponder
- 16,861
- 7
- 32
- 46

Chirag S
- 364
- 3
- 12