zoukankan      html  css  js  c++  java
  • 编程技巧(一)

    编程技巧(一)

    1.随机数
    // 初始化随机种子
    srandom((unsigned int)time(nil));
    // 得到随机浮点数
    float r = CCRANDOM_0_1();
    2.@property
    参考:子龙山人
    什么时候用assign、什么时候用retain和copy呢?推荐做法是NSString用copy,delegate用assign(且一定要用assign,不要问为什么,只管去用就是了,以后你会明白的),非objc数据类型,比如int,float等基本数据类型用assign(默认就是assign),而其它objc类型,比如NSArray,NSDate用retain。
    atomic是默认行为,assign是默认行为,readwrite是默认行为。
    3.NSMutableArray
    NSMutableArray *array;
    [array addObject:mapnode]; // 其原理为retain
    4.CCShow&CCHide
    id action1 = [CCShow action];
    id action2 = [CCHide action];
    5.在mac中方便地查看文件
    在终端中输入:ln -s "/Users/ketmales/Library/Application Support/iPhone Simulator/6.0/Applications/" /Users/ketmales/Documents/Applications
    注意,上面的ketmales是我的用户名,使用时注意使用自己的用户名。
    这样就可以方便地进入Applications目录了。
    6.文件路径
    NSString *filePath = [NSString stringWithFormat:@"%@/%@",
                              [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"],
                              fileName];
    7.shake
            if (shakeCnt % 2 == 0 && shakeCnt > 0) {
    		to = CGPointMake(orgCenter.x + floor(random() % shakeCnt) - shakeCnt / 2,
    						 orgCenter.y + floor(random() % shakeCnt) - shakeCnt / 2);
    	}else {
    		to = orgCenter;
    	}
    
    
  • 相关阅读:
    Spring事务隔离级别、传播机制、实现方式
    包装类缓存
    Object类详解
    String类详解
    自己实现一个Map
    锁机制
    各容器区别比较
    Map-CurrentHashMap
    Javascript中bind()方法的使用与实现
    this、new、call和apply的相关问题
  • 原文地址:https://www.cnblogs.com/ketmales/p/2892494.html
Copyright © 2011-2022 走看看