Skip to main content
spelling in title
Source Link
Cœur
  • 39k
  • 25
  • 206
  • 282

Problem with retreiving Retrieving Array data stored in plist File

I have a problem, howHow can we retrieve the array data stored in plist file.

The plist file and source code is as shown below,

------------------------plist File-------------------------
<?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>Name</key>
    <string>abcxxx</string>
    <key>Phones</key>
    <array/>
    <key>item1</key>
    <string>121327777</string>
    <key>item2</key>
    <string>333333333</string>
</dict>
</plist>
---------------------------------------------------------



  -(id) init
{
   
   
    NSString *errorDesc = nil;
    NSPropertyListFormat format;
    phoneNumbers =[[NSMutableArray alloc]init];
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"testfile" ofType:@"plist"];
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
   
    NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                          propertyListFromData:plistXML
                                          mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                          format:&format errorDescription:&errorDesc];
   
    if(!temp){
        NSLog(errorDesc);
        [errorDesc release];
    }
    self.personName = [temp objectForKey:@"Name"];
    self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
    NSLog(@"Label executed %@",[phoneNumbers objectAtIndex:0]);
   
    UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(-180, 100, 100, 20)];
    name.text = [phoneNumbers objectAtIndex:1];
    [self addChild:name];
    NSLog(@"Label executed %@",name);

Anyone help me on this.

Thanks in Advance,

Problem with retreiving Array data stored in plist File

I have a problem, how can we retrieve the array data stored in plist file.

The plist file and source code is as shown below,

------------------------plist File-------------------------
<?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>Name</key>
    <string>abcxxx</string>
    <key>Phones</key>
    <array/>
    <key>item1</key>
    <string>121327777</string>
    <key>item2</key>
    <string>333333333</string>
</dict>
</plist>
---------------------------------------------------------



  -(id) init
{
   
   
    NSString *errorDesc = nil;
    NSPropertyListFormat format;
    phoneNumbers =[[NSMutableArray alloc]init];
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"testfile" ofType:@"plist"];
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
   
    NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                          propertyListFromData:plistXML
                                          mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                          format:&format errorDescription:&errorDesc];
   
    if(!temp){
        NSLog(errorDesc);
        [errorDesc release];
    }
    self.personName = [temp objectForKey:@"Name"];
    self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
    NSLog(@"Label executed %@",[phoneNumbers objectAtIndex:0]);
   
    UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(-180, 100, 100, 20)];
    name.text = [phoneNumbers objectAtIndex:1];
    [self addChild:name];
    NSLog(@"Label executed %@",name);

Anyone help me on this.

Thanks in Advance,

Retrieving Array data stored in plist File

How can we retrieve the array data stored in plist file.

The plist file and source code is as shown below,

------------------------plist File-------------------------
<?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>Name</key>
    <string>abcxxx</string>
    <key>Phones</key>
    <array/>
    <key>item1</key>
    <string>121327777</string>
    <key>item2</key>
    <string>333333333</string>
</dict>
</plist>
---------------------------------------------------------



  -(id) init
{
   
   
    NSString *errorDesc = nil;
    NSPropertyListFormat format;
    phoneNumbers =[[NSMutableArray alloc]init];
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"testfile" ofType:@"plist"];
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
   
    NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                          propertyListFromData:plistXML
                                          mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                          format:&format errorDescription:&errorDesc];
   
    if(!temp){
        NSLog(errorDesc);
        [errorDesc release];
    }
    self.personName = [temp objectForKey:@"Name"];
    self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
    NSLog(@"Label executed %@",[phoneNumbers objectAtIndex:0]);
   
    UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(-180, 100, 100, 20)];
    name.text = [phoneNumbers objectAtIndex:1];
    [self addChild:name];
    NSLog(@"Label executed %@",name);
fixed formatting
Source Link
Andy White
  • 88.7k
  • 48
  • 178
  • 212

------------------------plist File-------------------------

NameabcxxxPhonesitem1121327777item2333333333---------------------------------------------------------

-(id) init {

------------------------plist File-------------------------
<?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>Name</key>
    <string>abcxxx</string>
    <key>Phones</key>
    <array/>
    <key>item1</key>
    <string>121327777</string>
    <key>item2</key>
    <string>333333333</string>
</dict>
</plist>
---------------------------------------------------------



  -(id) init
{
   
   
    NSString *errorDesc = nil;
    NSPropertyListFormat format;
    phoneNumbers =[[NSMutableArray alloc]init];
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"testfile" ofType:@"plist"];
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
   
    NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                          propertyListFromData:plistXML
                                          mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                          format:&format errorDescription:&errorDesc];
   
    if(!temp){
        NSLog(errorDesc);
        [errorDesc release];
    }
    self.personName = [temp objectForKey:@"Name"];
    self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
    NSLog(@"Label executed %@",[phoneNumbers objectAtIndex:0]);
   
    UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(-180, 100, 100, 20)];
    name.text = [phoneNumbers objectAtIndex:1];
    [self addChild:name];
    NSLog(@"Label executed %@",name);

------------------------plist File-------------------------

NameabcxxxPhonesitem1121327777item2333333333---------------------------------------------------------

-(id) init {

NSString *errorDesc = nil;
NSPropertyListFormat format;
phoneNumbers =[[NSMutableArray alloc]init];
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"testfile" ofType:@"plist"];
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];

NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                      propertyListFromData:plistXML
                                      mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                      format:&format errorDescription:&errorDesc];

if(!temp){
    NSLog(errorDesc);
    [errorDesc release];
}
self.personName = [temp objectForKey:@"Name"];
self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
NSLog(@"Label executed %@",[phoneNumbers objectAtIndex:0]);

UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(-180, 100, 100, 20)];
name.text = [phoneNumbers objectAtIndex:1];
[self addChild:name];
NSLog(@"Label executed %@",name);
------------------------plist File-------------------------
<?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>Name</key>
    <string>abcxxx</string>
    <key>Phones</key>
    <array/>
    <key>item1</key>
    <string>121327777</string>
    <key>item2</key>
    <string>333333333</string>
</dict>
</plist>
---------------------------------------------------------



  -(id) init
{
   
   
    NSString *errorDesc = nil;
    NSPropertyListFormat format;
    phoneNumbers =[[NSMutableArray alloc]init];
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"testfile" ofType:@"plist"];
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
   
    NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                          propertyListFromData:plistXML
                                          mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                          format:&format errorDescription:&errorDesc];
   
    if(!temp){
        NSLog(errorDesc);
        [errorDesc release];
    }
    self.personName = [temp objectForKey:@"Name"];
    self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
    NSLog(@"Label executed %@",[phoneNumbers objectAtIndex:0]);
   
    UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(-180, 100, 100, 20)];
    name.text = [phoneNumbers objectAtIndex:1];
    [self addChild:name];
    NSLog(@"Label executed %@",name);
Source Link
bhanu
bhanu

Problem with retreiving Array data stored in plist File

I have a problem, how can we retrieve the array data stored in plist file.

The plist file and source code is as shown below,

------------------------plist File-------------------------

Name abcxxx Phones item1 121327777 item2 333333333 ---------------------------------------------------------

-(id) init {

NSString *errorDesc = nil;
NSPropertyListFormat format;
phoneNumbers =[[NSMutableArray alloc]init];
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"testfile" ofType:@"plist"];
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];

NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                      propertyListFromData:plistXML
                                      mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                      format:&format errorDescription:&errorDesc];

if(!temp){
    NSLog(errorDesc);
    [errorDesc release];
}
self.personName = [temp objectForKey:@"Name"];
self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
NSLog(@"Label executed %@",[phoneNumbers objectAtIndex:0]);

UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(-180, 100, 100, 20)];
name.text = [phoneNumbers objectAtIndex:1];
[self addChild:name];
NSLog(@"Label executed %@",name);

Anyone help me on this.

Thanks in Advance,