ios App里数据存取


记录数据:

1)数据在app关掉,下一次打开还在;

存数据:

NSString *last_uuid = [NSString stringWithFormat:@"%s", uuid];
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        [ud setObject:last_uuid forKey:@"last_device"];

取数据:

    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    NSString *last_uuid = [ud stringForKey:@"last_device"];

2)数据在app关掉,下一次打开不在,但在切换view后还在;

-----------------------------------------

@interface DeviceMgr : NSObject

@property (nonatomic, readwrite) NSMutableArray *devices;  //Device

@property (nonatomic, readwrite) int             device_count;  //设备
@property (nonatomic, readwrite) BOOL            b_remember;    //记忆设备
@property (nonatomic, readwrite) int            g_volume;
@property (nonatomic, readwrite) int            g_brightness;

+(id)SharedDevices;

---------------------------------------

@implementation DeviceMgr
+(id)SharedDevices
{
    static DeviceMgr *device_mgr = nil;
    if (device_mgr == nil) {
        device_mgr = [[DeviceMgr alloc] init];
    }
    return device_mgr;
}

-------------------------------------------

应用

存数据:

DeviceMgr *device_mgr = [DeviceMgr SharedDevices];
        //device_mgr.g_brightness = shift_brightness;
        device_mgr.g_volume = shift_volume;

取数据:

DeviceMgr *device_mgr = [DeviceMgr SharedDevices];

        shift_brightness = device_mgr.g_brightness;
        shift_volume = device_mgr.g_volume;


----------------------------------------------


你可能感兴趣的:(ios App里数据存取)