从0开始学习OC程序-第13天

来源:互联网 发布:打预防针下载什么软件 编辑:程序博客网 时间:2024/06/04 19:34

Foundation 框架简单学习

////  main.m//  Foundation学习////  Created by 北国 on 16/3/18.//  Copyright © 2016年 beiguo. All rights reserved.//#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) {    @autoreleasepool {        NSString *str = @"i love oc";        NSRange r = NSMakeRange(2, 4);        NSRange nsr = [str rangeOfString:@"love"];        NSLog(@"location = %ld,length=%ld",nsr.location,nsr.length);        NSPoint np = CGPointMake(10, 20);        CGRect cr = CGRectMake(0, 0, 0, 0);        NSString *st1 = @"123";        //C语言字符串转成OC字符串        NSString *st2 = [[NSString alloc] initWithUTF8String:"xxx"];        //OC字符串转成C语言字符串        char *cs = [st2 UTF8String];        //从字符串中读取然后显示给用户        NSString *st3 = [[NSString alloc]initWithContentsOfFile:@"/User/..." encoding:NSUTF8StringEncoding error:nil];        //NSString 为不可变字符串        //NSMutableString 可变字符串        NSMutableString * nus = [NSMutableString stringWithFormat:@"haha"];        [nus appendString:@"eee"];        NSLog(@"%@",nus);        NSRange nr11 = [nus rangeOfString:@"ae"];        [nus deleteCharactersInRange:nr11];        NSLog(@"%@",nus);        //NSArray 不可变 NSMutableArray 可变数组        NSArray *array = @[@"wwww",@"xxxx"];        for (id obj in array) {            NSLog(@"array is %@",obj);        }        //NSSet 没有顺序的集合        NSSet *set = [NSSet set];        NSSet *set1 = [NSSet setWithObjects:@"xx",@"xxx",@"xxxx", nil];        NSString *stttt = [set1 anyObject];        NSLog(@"stttt is %@",stttt);        //NSDictionary NSMutableDicionary        NSDictionary *dict = @{@"name" : @"北国",@"address":@"黑龙江"};        id obj = dict[@"name"];        //字典遍历        NSArray *keys = [dict allKeys];        for (int i=0; i<dict.count; i++) {            NSLog(@"key is %@, value is %@",keys[i],dict[keys[i]]);        }        NSLog(@"%@",obj);    }    return 0;}
0 0
原创粉丝点击