zoukankan      html  css  js  c++  java
  • UISB UserDefaults

    ViewController.m

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.frame=CGRectMake(100, 100, 80, 40);
        [btn setTitle:@"write" forState:UIControlStateNormal];
        
        [btn addTarget:self action:@selector(presswrite) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:btn];
        
        UIButton* btnRead=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        btnRead.frame=CGRectMake(100, 200, 80, 40);
        [btnRead setTitle:@"read" forState:UIControlStateNormal];
        
        [btnRead addTarget:self action:@selector(pressread) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:btnRead];
            
        
    }
    
    -(void)presswrite
    {
        
        //用户默认数据对象
        //不需要alloc 单例模式
        //standardUserDefaults 获取全局唯一的实例对象
        NSUserDefaults* ud =[NSUserDefaults standardUserDefaults];
        
        //存储字符串对象
        //P1 存储对象
        //P2 对象的名字
        [ud setObject:@"kobe" forKey:@"Name"];
        
        NSNumber* num =[NSNumber numberWithInt:100];
        
        [ud setObject:num forKey:@"Num"];
        
        [ud setInteger:123 forKey:@"INI"];
        [ud setBool:YES forKey:@"Bool"];
        [ud setFloat:1.555 forKey:@"Float"];
        
        // 创建一个可文件化的数据
        NSArray* array = [NSArray arrayWithObjects:@"11",@"22",@"33",nil];
        [ud setObject:array forKey:@"ABBA"];
        
        
      
        
    }
    
    -(void)pressread
    {
        NSUserDefaults* ud = [NSUserDefaults standardUserDefaults];
        
        id object = [ud objectForKey:@"Name"];
        NSString* name =(NSString*) object;
        NSLog(@"name=%@",name);
        
        object = [ud objectForKey:@"Num"];
        NSNumber* num=(NSNumber*) object;
        NSLog(@"num=%@",num);
        
        NSInteger iv = [ud integerForKey:@"INI"];
        NSLog(@"iv=%ld",iv);
        
        
        
        
        
        
    }
    
    
    @end
  • 相关阅读:
    解决input 输入框频繁请求问题,如果拿取最后一次接口返回的值
    记录两个小问题
    axios 如何取消请求
    给vue组件绑定原生事件
    Vue3 与 Vue2的不同之处一 简单介绍 Vue 核心最基本的功能
    js将数组对象中,以某个值相同的对象合并成一个;即把某个值相同的对象内容合并成一个
    postcss-preset-env
    webpack5 tree shaking
    深拷贝
    webpack 性能优化
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13789270.html
Copyright © 2011-2022 走看看