2011-08-04 1 views
2

オブジェクトの配列(フィールド:タイトル、説明、日付)を日付順に並べているとします。リストからアイテムを選択し、それをローカルデバイスに保存します。次に、日付順の配列(UITableView)に格納された項目のリストをロードします。iOS - データの保存に使用するもの

私はコアデータを使用することは過剰なことだと思います。あなたは何をどのように使っていますか? THx!

答えて

3

私は、クラスNSCodingを実装し、NSKeyedArchiverを使用してファイルにオブジェクトを保存するようにします。

ディレクトリをループして、すべてのオブジェクトをNSKeyedUnarchiverでロードできます。

+0

Ow ... true ...オブジェクトをバイナリデータとして保存します。 – xpepermint

+0

よく 'NSKeyedUnarchiver'はplistファイルを使います.plistファイルはバイナリやXMLでもかまいません。 – rckoenes

0

さてあなたはあまりにもSQLitePlistのオプションを持っている...

あなたは、アレイ内の、あまりにも多くのアイテムを持っていない場合は、データのソートが...

1

容易になるだろうと私はSQLiteを好みますいくつかの種類のXMLソリューションを使用すると完璧です。

バックエンドストレージは人間が読み取り可能で編集可能なため、plistsは素晴らしいです。また、辞書や配列を容易にplistに変換するための機能が組み込まれています。例えば(writeToFile:atomically:)および(arrayWithContentsOfFile:

注意:配列/辞書にNSString、NSData、NSArray、NSDictionaryのいずれかの項目しか含まれていない場合にのみ、これらのメソッドを使用できます。そうでなければ、少しだけ多くの作業を行うNSCodingを実装する必要があります。

多くの利点がありますので、読み込み/検索に時間がかかる場合は、切り替えを検討してください。

0

PListを使用して、iphoneアプリケーションでデータを保存する最も簡単で簡単な方法です。私はあなたにそのことを教えてくれるでしょう。

これは、Plistにデータを保存する方法です。

//Create String to get data ... 

NSString *typeUrl = [NSString stringWithFormat:@"%@",url.text]; 

// Create Plist File 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"url.plist"]; 

NSString *tempurl = [NSString stringWithFormat:@"%@",typeUrl]; 

// Remove data previously stored in plist file ... 

[[NSFileManager defaultManager] removeItemAtPath:path error:NULL]; 

// Create NSMutableArray to Store your string ... 

NSMutableArray urlDetails = [[NSMutableArray alloc] init]; 

// Add String to Array ... 
[urlDetails addObject:tempurl]; 

// Store that array in Plist File ... 

[urlDetails writeToFile:path atomically:YES]; 

これは、Plistからデータを読み取る方法です。

// Find Plist file you created and cheack that file exsist ... 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"password.plist"]; 
    BOOL passwordfileExists = [[NSFileManager defaultManager] fileExistsAtPath:path]; 

    // if the file exsist create NSMutableArray and read the value and put that in to the String 

    if (passwordfileExists == YES) { 
     NSMutableArray* plistDict = [[NSMutableArray alloc] initWithContentsOfFile:path]; 
     NSString *value = [NSString stringWithFormat:@"%@",[plistDict objectAtIndex:0]]; 

     // Set that string to the textField 

     oldpassText = [NSString stringWithFormat:@"%@",value]; 
    } 

これは、私がPlistファイルとそのsooでデータを保存する方法です。私はこれがあなたを助けると思う。

関連する問題