How to Save NSMutableArray into plist in iphone

后端 未结 4 1784
执笔经年
执笔经年 2020-12-10 18:42

I am new in iphone, i want to save NSMutableArray data into plist file my Code is:

NSArray *array = [[NSArray alloc] initWithArray:self.artistDetailsArray];
         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 19:37

    NSData *serializedData;
            NSString *error;
            serializedData = [NSPropertyListSerialization dataFromPropertyList:YourArray(You can use dictionaries.strings..and others too)
            format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
            if (serializedData) {
            // Serialization was successful, write the data to the file system // Get an array of paths.
    
           NSArray *documentDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *docDir = [NSString stringWithFormat:@”%@/serialized.xml”,
             [documentDirectoryPath objectAtIndex:0]];
            [serializedData writeToFile:docDir atomically:YES];
     }
            else {
            // An error has occurred, log it
            NSLog(@”Error: %@”,error); }
            }
    

提交回复
热议问题