• 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
  • 相关阅读:
    CGI与fastcgi
    【总结】手动配置LNMP环境之安装NMP
    yum方式安装的Apache目录详解和配置说明
    W. Mysql
    V. PHP
    U. Apache
    学习进度条博客16
    构建之法阅读笔记05
    构建之法阅读笔记04
    构建之法阅读笔记03
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13789270.html
Copyright © 2020-2023  润新知