小编iPh*_*e4s的帖子

如何将NSMutableArray保存到iphone中的plist中

我是iphone的新手,我想将NSMutableArray数据保存到plist文件中,我的代码是:

NSArray *array = [[NSArray alloc] initWithArray:self.artistDetailsArray];
[self.artistDetailsArray writeToFile:self.path atomically:YES];
Run Code Online (Sandbox Code Playgroud)

但它在我的plist路径中显示0个元素.请任何帮助我.

提前致谢:

以下是我将数据存储到plist和NSUserDefault的代码.它们都不适用于NSMutableArray/NSArray,但适用于NSString.是否存在plist或UserDefault中存储的最大大小限制?NSMutableArray仅包含NSDictionary的文本/集.

请建议我.

- (void)initialiseDataFromLocalStorage
{
       NSFileManager *fileManager = [NSFileManager defaultManager];
       NSError *error;
       NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
       NSString *documentsDirectory = [paths objectAtIndex:0];
       self.path = [documentsDirectory stringByAppendingPathComponent:@"saveLogin.plist"];
       if ([fileManager fileExistsAtPath:self.path] == NO) {
               NSString *pathToDefaultPlist = [[NSBundle mainBundle] pathForResource:@"saveLogin" ofType:@"plist"];
               if ([fileManager copyItemAtPath:pathToDefaultPlist toPath:self.path error:&error] == NO) {
                       NSAssert1(0,@"Failed with error '%@'.", [error localizedDescription]);
               }
       }

   // To get stored value from .plist
       NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:self.path]; …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c plist

5
推荐指数
2
解决办法
1万
查看次数

如何从iPhone中的SQLite数据库中删除表数据

我正在研究SQLite数据库.我正在将数据插入到数据库中,这很好.但我想删除数据库中的数据不起作用,我想我做错了以下是我的代码,请任何人帮助我:

-(IBAction)deleteData {

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath=[documentsDir stringByAppendingPathComponent:@"paddleEight.sqlite"];
NSLog(@"The Database Path is---> %@", databasePath);

sqlite3_stmt *compiledStatement;
sqlite3 *db;
NSString *sqlStatement = @"DELETE  from GalleryTabel;";


if (sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK) {


    if (sqlite3_prepare(db, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"record" message:@"record Deleted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];   
        [alert show];
        [alert release];
        alert=nil;
    }
    sqlite3_finalize(compiledStatement);
}
}
Run Code Online (Sandbox Code Playgroud)

sqlite iphone objective-c

0
推荐指数
1
解决办法
5922
查看次数

标签 统计

iphone ×2

objective-c ×2

plist ×1

sqlite ×1