How to save data , in an iOS application?

前端 未结 6 781
伪装坚强ぢ
伪装坚强ぢ 2021-01-16 18:23

I am developing an application where the user creates an event which has 3 fields:

Category , name , event. After the user gives his entry , i have a save

6条回答
  •  不要未来只要你来
    2021-01-16 19:09

    For saving data via NSUserDefaults I'm using GVUserDefaults

    Usage

    Create a category on GVUserDefaults, add some properties in the .h file and make them @dynamic in the .m file.

    // .h
    @interface GVUserDefaults (Properties)
    @property (nonatomic, weak) NSString *userName;
    @property (nonatomic, weak) NSNumber *userId;
    @property (nonatomic) NSInteger integerValue;
    @property (nonatomic) BOOL boolValue;
    @property (nonatomic) float floatValue;
    @end
    

    // .m
    @implementation GVUserDefaults (Properties)
    @dynamic userName;
    @dynamic userId;
    @dynamic integerValue;
    @dynamic boolValue;
    @dynamic floatValue;
    @end
    

    Now, instead of using [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"], you can simply use [GVUserDefaults standardUserDefaults].userName.

    You can even save defaults by setting the property:

    [GVUserDefaults standardUserDefaults].userName = @"myusername";
    

提交回复
热议问题