9/17/2014Record my struggle time learning the ios dev.

       感觉自己应当学习别的优秀的程序员他们可贵的品质:勤于记录自己的学习历程,并且乐于同他人讨论和请教自己不同的地方,这是成为一个职业coder所必需的品质。我也应该从现在开始get started。

       1>当然是每天总结并且在这个blog上写下当天的学习知识和内容,老师讲过的理论内容,自己理解了哪些方面,还有什么地方是自己不了解的,具体是哪一点不是很清楚,想办法求助百度,再请教同学和老师。

       2>最重要的是当天的知识能否通过实际的代码来实现,直观的反映所学的理论知识和实际上的coding的结合,加深理论的理解,同时也促进类编程的学习。

       3>对于比较重要的知识点,采取扫描以点带面,点对点突破的原则,看看能否融入到自己的代码中来学习。现在的阶段并不是买多少纸质书的问题,不说花了大价钱,而且实际上并不会有太多的时间和良好的阅读环境提供给你的,更多和更加实际的方式反倒是能否将每个知识每个难懂的point在我们的xcode中实现是最重要的。

       其实,说千句道万遍都不如敲代码来得实际一点,而且下定决心身上背负类沉重贷款的代价也要来学习iOS开发,为的就是希望自己能够博得一个较为光明的就业前景,面对前路的坎坷和崎岖难行,怎能同流合污般的安于享乐,我可不想延迟结业,只要别人行的,我相信自己终究可以做得到,这其中的过程无论是时间的延长还是精力的耗费,都在所不惜。

       复习昨天讲过的内容:深拷贝的实现方式:是通过归档和接档的方式来进行.

- (NSArray *)deepMutableCopy
{

    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self];
    NSArray *deepCopy = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    

    return deepCopy;
}

       分类的方法和具体的操作,跟java中的借口功能相似,当然也可以直接用子类继承父类的方法,但是这样可以更方便,因为只需要扩展既有类的功能方法就可以,但是只能扩展方法,不能声明属性特征。原因在于苹果开发源码的不开源,只给我们提供了接口和方法的声明,具体里面方法的实现并没有得到开放,但是如果是我们自己定义的类,就没必要用分类的方法了,直接可以在类的.m文件里面来实现我们的方法就可以类,其实通俗一点讲:分类就是方法的实现,二者可以按相同的观点来看待和处理。除了加上分类一个比较特殊的地方:NSArray(ReverseString)这样的方式来代表我们扩展的方法ReverseString是对既有的NSArray进行方法上的扩充的,除此,别无他尔。

       过几天马上就要进行OC的阶段性的测试了,对于结果的担心并不是来源自以前类似大学挂科般的压力,而是身上背负沉重的贷款所赋予自己的压力和家人另外还有自己对一定要学好别人都可以我为什么不行的决定和血性的抗争到底不服输的勇气和精神。所以当然要经全力来搞好它了,反正这几个月我想除了攻克iOS之外,应该没有什么其他的重点,对于这一点希望你要搞明白。

        要对NSString的增删查改,编译器会报错的,所以最好都是按照一下的方法来进行设置:

       NSString *string = @"Hello World"; 这样的创建对象string的方式只能用作打印NSLog,如果一旦要进行修改的话,就不行了,最明显受挫的就是调用已经声明和定义的方法的时候,编译器不会进行任何的提示,即使你强自写完也不免悲剧的错误了.就如下图所示.

        //注意:此处的string一定要设为NSMutableString,否则调用方法的时候,根本就不会提示方法,即错了.
       

       NSString *string = @"Hello World!";要改成:NSMutableString *string = [@"Hello World!"mutableCopy];

       NSString改为NSMutableString是为了对string进行操作.  而在后面再加上mutableCopy的方法,则是对@""里面的字符串进行深拷贝,即另外获取一个独立的内存地址用来存放副本的字符串.如果没有的话,编译器报错的提示如下:    
      NSMutableString *string = @"Hello World!";        !Incompatible pointer types initializing 'NSMutableString *' with an expression of type 'NSString *'.

       以后这样的报错提示基本上都可以按照这样的方法处理:就是在后面再加上一个方法消息;  [@[ ] MutableCopy];

       NSLog(@"Original:%@",string);

       [string reverseString];
       
       NSLog(Reverse string:%@", string);
        
      }
      return 0;
}


      assign: 简单赋值,不更改索引计数(Reference Counting)。
      copy: 建立一个索引计数为1的对象,然后释放旧对象
      retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1
      retain的实际语法为:

    - (void)setName:(NSString *)newName {
    if (name != newName) {
    [name release];
    name = [newName retain];

    // name’s retain count has been bumped up by 1}}说了那么麻烦,其实接下来的话最重要:
    使用assign: 对基础数据类型 (NSInteger,CGFloat)和C数据类型(int, float, double, char, 等等)
    使用copy: 对NSString
    使用retain: 对其他NSObject和其子类
    atomic是Objc使用的一种线程保护技术,基本上来讲,是防止在写未完成的时候被另外一个线程读取,造成数据错误。而这种机制是耗费系统资源的,所以在iPhone这种小型设备上,如果没有使用多线程间的通讯编程,那么nonatomic是一个非常好的选择。   



       #import "NSMutableString+Reverse.h"

      @implementation NSMutableString (Reverse)
       - (void)reverseString{
//    NSMutableString *str = self;
//    for (int i = (int)self.length - 1; i>=0; i--) {
//        NSMutableString *s = [[self substringWithRange:NSMakeRange(i,1)] mutableCopy];
//        
//        [str deleteCharactersInRange:NSMakeRange(i, 1)];
//        [str appendString:s];
//    }
//    }

    for (int i = 0 ; i<self.length/2; i++) {
        NSRange beginRange = NSMakeRange(i, 1);
        NSRange endRange = NSMakeRange(self.length-1-i, 1);
        NSString *begingSub = [self substringWithRange:NSMakeRange(i, 1)];
        NSString *endSub = [self substringWithRange:NSMakeRange(self.length-1-i, 1)];
        [self replaceCharactersInRange:endRange withString:begingSub];
        [self replaceCharactersInRange:beginRange withString:endSub];
    }
}
@end


        - (NSUInteger)sideCount
{
        int sum = 0;
    
        for (Shape *shape in self.shapes) {
        if ([shape isKindOfClass:[Rectangle class]]) {
            sum +=  4;
        }
        else if ([shape isKindOfClass:[Ellipse class]]) {
            sum += 0;
        }
        else if ([shape isKindOfClass:[Triangle class]]) {
            sum += 3;
        }
        }
    
       return sum;
}

@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Based on the following story, continue the story by writing two paragraphs, paragraph 1 beginning with "A few weeks later, I went to the farm again. " and paragraph 2 beginning with "I was just about to leave when the hummingbird appeared."respectively with 150 words. I was invited to a cookout on an old friend's farm in western Washington. I parked my car outside the farm and walked past a milking house which had apparently not been used in many years.A noise at a window caught my attention,so I entered it. It was a hummingbird,desperately trying to escape. She was covered in spider-webs and was barely able to move her wings. She ceased her struggle the instant I picked her up. With the bird in my cupped hand, I looked around to see how she had gotten in. The broken window glass was the likely answer. I stuffed a piece of cloth into the hole and took her outside,closing the door securely behind me. When I opened my hand, the bird did not fly away; she sat looking at me with her bright eyes.I removed the sticky spider-webs that covered her head and wings. Still, she made no attempt to fly.Perhaps she had been struggling against the window too long and was too tired? Or too thirsty? As I carried her up the blackberry-lined path toward my car where I kept a water bottle, she began to move. I stopped, and she soon took wing but did not immediately fly away. Hovering,she approached within six inches of my face. For a very long moment,this tiny creature looked into my eyes, turning her head from side to side. Then she flew quickly out of sight. During the cookout, I told my hosts about the hummingbird incident. They promised to fix the window. As I was departing, my friends walked me to my car. I was standing by the car when a hummingbird flew to the center of our group and began hovering. She turned from person to person until she came to me. She again looked directly into my eyes, then let out a squeaking call and was gone. For a moment, all were speechless. Then someone said, “She must have come to say good-bye.”
02-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值