学习object-c的一些笔记

1. 类 ,对象,属性,成员变量,局部变量,方法,函数,行为。

  类:一类抽象的事物   对象:类的具体实现   函数=方法=行为:可以简单的这么理解成是一样的,类的一种动作  属性:封装了成员变量的get setter方法  成员变量:类中定义的变量,作用域是整个类  局部变量:方法中定义的一个变量,作用的域是这个方法

  调用属性 self.属性

  调用类方法 Person *p =[Person alloc]init ];

  调用实例方法   NSString *变量 = @"hello the word";      [变量 writeToFile(实例方法):@""];

2. 数据类型

   int  float double 一般的数据类型 不涉及内存的操作

   NSString  NSSArray ... OC中的数据类型 其实他是对象 所以涉及到内存管理。

3.定义一个字符串类型的变量可以用以下几种方法

    NSString *str = @"hello word"     

    NSString *str = [NSString stringWithFormat:@"%@",@"hello word"]

    以上两种都是常见的创建字符串的方法,第一种是在常量池中创建一个字符串,如果有相同的字符串都会指向同一个,第二种是在堆中创建一个对象,如果有相同的相当于创建了两个对象。

     注:NSString * *str =@"hello word" -> 应该是指该字符串中栈的地址吧

4.一些将磁盘中的文件读取到内存的方法:

      1).磁盘文件 --> 内存代码

       方法-:

      NSString *text = [NSSring stringWithContentOfFile:@"/workspace/test.txt" encoding:NSUTF8StringEncoding error:&error]

        方法二:

      NSURL *url = [NSURL URLWithString:@"/workspace/test.txt"];

      NSString *text = [NSString stringWithContentOfURL:url encoding:NSUTF8StringEncoding error:&error];

       2).内存代码中的字符串 --> 磁盘文件

          方法一:前提条件是路径没有中文

      NSString *str = @"hello the word";

      [str writeToFile:@"/workspace/text.txt  atomically:YES encoding:NSUTF8StringEncoding error:nil"];

          方法二:  这种路径可以有中文

      [str writeToURL:[NSURL fileURLWithPath:@"/workspace/text.txt"] atomically:YES  encoding:NSUTF8StringEncoding error:nil];

      注解:这两个方法挺重要的后面的 json数据解析估计会用到, atomically: 原子的,如果文件写入不完整,则不回创建文件。

5.字符串常用的方法:

    1)转化成大写:

           NSString *s1 = @"hehehe";

           s1 = [s1  uppercaseString]

     2)  转换成小写

            NSString *s2 = @"hahaha";

            s2 = [s2  lowercaseString]

            

    

posted on 2015-08-16 00:10  技生瑜合声靓  阅读(119)  评论(0编辑  收藏  举报

导航