Änderungen speichern

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Änderungen speichern

    Hallo habe eine Todo List geschrieben als Mac App.
    Alles funktioniert auch soweit gut doch habe ich ein großes Problem.
    Und zwar weiß ich nicht wie man die Ereignisse die jemand eingibt auch nach dem schließen der app speichern kann.
    Also das wenn ich die App neu öffne die Daten noch da sind.
    Wie kann man das machen ?
    Kenne das nur aus Java mit Serialisierung.
    Danke
  • kann ich dir das Projekt vielleicht mal schicken und du schaust was ich verkehrt habe ?! blicke einfach nicht mehr durch und wenn ich das noch implementiert bekommen würde wäre ich sehr zufrieden
  • achso ok schade dachte nur weil es sich so anhörte als wäre es eine sache von 5min =)
    also ich habe eine funktion
    -(void)readPlist {
    }
    und habe darin versucht die writeToFile Methode zu implementieren
  • d.h ist mache 2 funktionen eine readPlist und eine writePlist
    und wenn ein ereignis erstellt wurde dann schreibe ich die änderungen in die plist und bei jedem start lass ich das programm die daten aus der plist lesen
    das schaffe ich nie :D
  • Habe nun folgendes : weiß nun nur nicht wie ich dem programm sagen soll wann es das machen soll also wann es schreiben bzw lesen soll

    Quellcode

    1. - (void) lesen {
    2. NSError *error;
    3. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
    4. NSString *documentsDirectory = [paths objectAtIndex:0]; //2
    5. NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"]; //3
    6. NSFileManager *fileManager = [NSFileManager defaultManager];
    7. if (![fileManager fileExistsAtPath: path]) //4
    8. {
    9. NSString *bundle = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; //5
    10. [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
    11. }
    12. NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
    13. //load from savedStock example int value
    14. int value;
    15. value = [[savedStock objectForKey:@"value"] intValue];
    16. [savedStock release];
    17. }
    18. - (void) schreiben {
    19. NSError *error;
    20. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
    21. NSString *documentsDirectory = [paths objectAtIndex:0]; //2
    22. NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"]; //3
    23. NSFileManager *fileManager = [NSFileManager defaultManager];
    24. if (![fileManager fileExistsAtPath: path]) //4
    25. {
    26. NSString *bundle = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; //5
    27. [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
    28. }
    29. NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
    30. //here add elements to data file and write data to file
    31. int value = 5;
    32. [data setObject:[NSNumber numberWithInt:value] forKey:@"value"];
    33. [data writeToFile: path atomically:YES];
    34. [data release];
    35. }
    Alles anzeigen
  • Ok habe nun folgendes bekomme keine Fehler aber es passier auch nichts mit meiner plist

    Quellcode

    1. #import "ToDoListAppDelegate.h"
    2. #import "ToDoItem.h"
    3. @implementation ToDoListAppDelegate
    4. @synthesize window;
    5. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    6. NSError *error;
    7. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
    8. NSString *documentsDirectory = [paths objectAtIndex:0]; //2
    9. NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"]; //3
    10. NSFileManager *fileManager = [NSFileManager defaultManager];
    11. if (![fileManager fileExistsAtPath: path]) //4
    12. {
    13. NSString *bundle = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; //5
    14. [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
    15. }
    16. NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
    17. //load from savedStock example int value
    18. int value;
    19. value = [[savedStock objectForKey:@"value"] intValue];
    20. [savedStock release];
    21. }
    22. - (void)applicationWillTerminate:(NSNotification *)notification {
    23. NSError *error;
    24. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
    25. NSString *documentsDirectory = [paths objectAtIndex:0]; //2
    26. NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"]; //3
    27. NSFileManager *fileManager = [NSFileManager defaultManager];
    28. if (![fileManager fileExistsAtPath: path]) //4
    29. {
    30. NSString *bundle = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; //5
    31. [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
    32. }
    33. NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
    34. //here add elements to data file and write data to file
    35. int value = 5;
    36. [data setObject:[NSNumber numberWithInt:value] forKey:@"value"];
    37. [data writeToFile: path atomically:YES];
    38. [data release];
    39. }
    40. - (IBAction)addNewToDoItem:(id)sender
    41. {
    42. ToDoItem *newToDo = [[ToDoItem alloc] init];
    43. [newToDo setIsFinished:false];
    44. [newToDo setTimestamp:[NSDate date]];
    45. [newToDo setPriority:[NSNumber numberWithInt:5]];
    46. [newToDo setHeadline:@"Neue Aufgabe"];
    47. [newToDo setNote:@"leer"];
    48. [doToItemsArrayController addObject:newToDo];
    49. }
    50. - (IBAction)removeToDoItem:(id)sender
    51. {
    52. [window endEditingFor:nil];
    53. NSArray *items = [doToItemsArrayController selectedObjects];
    54. [doToItemsArrayController removeObject:items];
    55. }
    56. @end
    Alles anzeigen
  • ok du sagtest du würdest mir helfen gegen bezahlung ich würde folgendes vorschlagen:
    -das speichern der daten
    -man soll anfangsdatum und enddatum angeben könnnen und den tag aus einem gregorianischen kalender auswählen können

    Wieviel würdest du dafür nehmen ?
    schreib mir eine email an osprogramming@web.de