zoukankan      html  css  js  c++  java
  • iOS开发-开发总结(五)

    一:@autoclosure将一段代码块活着一句表达式自动的封装成一个闭包
    func logIfTrue(predicate: () -> Bool) {  if predicate() { 
    
               print("True")
           }
    } 

    调用

    • logIfTrue({return 2 > 1}) 简写:logIfTrue{2 > 1}

    在predicate加上@autoclosure调用的时候就可以省略{}直接使用logIfTrue(2>1)





    二:??的定义:
    • func ??<T>(optional: T?, @autoclosure defaultValue: () -> T?) -> T?


    三:闭包:
    • ({()->() in
    • })


    四:操作符重载:
    • func +(left: Vector2D, right: Vector2D) -> Vector2D { return Vector2D(x: left.x + right.x, y: left.y + right.y)

    五:错误-Operator implementation without matching operator declaration 

    因为没有对操作符进行声明

    • infix operator +* { associativity none precedence 160
    • infix 
    • associativity
    • precedence 

    六 :NSAutoreleasePool实现

        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        int retVal = UIApplicationMain(argc, argv, nil, nil);
        [pool release];
        return retVal;

    七:关于懒加载:

    • OC
    复制代码
     1 @property (nonatomic, strong) NSArray *dataArray;
     2 
     3 //重写get方法
     4 - (NSArray *)dataArray
     5 {
     6     if (nil == _dataArray){
     7         _dataArray = [NSArray array];
     8     }
     9     return _dataArray
    10 }
    复制代码
    • Swift

    你可以这样简单的实现

    复制代码
    1 //1.分析 NSArray 是一个闭包的返回值,而这是一个没有参数的闭包
    2     lazy var dataArray:NSArray = {
    3         return []
    4     }()
    5 
    6     //2.也可以写成这样
    7     lazy var dataArray:NSArray = {
    8         return NSArray()
    9     }()
    复制代码

    但是我们一般都是这么加载一些数据

    复制代码
     1 //3.从plist文件加载
     2    lazy var dataArray:Array<XWWine> = {
     3             let winePath = NSBundle.mainBundle().pathForResource("wine.plist", ofType: nil)!
     4 
     5             let winesM = NSMutableArray(contentsOfFile: winePath);
     6 
     7             var tmpArray:Array<XWWine>! = []
     8 
     9             for tmpWineDict in winesM! {
    10 
    11                 var wine:XWWine = XWWine.wineWithDict(tmpWineDict as!                 NSDictionary)
    12 
    13                   tmpArray.append(wine)
    14             }
    15 
    16             print("我就运行一次")
    17 
    18             return tmpArray
    19     }()
    复制代码
     
    八:设置状态栏样式
     
    • 第一步:在info.plist中添加一个字段:view controller -base status bar 设置为NO
     
    • 第二步:在一个所有界面都继承的父类里添加:
    1.   if (IOS8_OR_LATER) { // 判断是否是IOS8
    2.     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContentanimated:NO];
    3.   }
     
     
    九:实用KVC方式修改文本框(UITextField)内部placeholer的属性(后面我们会说到使用自定义UItextView的方式实现)
     
    textField.placeholder = @"username is in here!";  
    [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];  
    [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];  
    这里是使用了KVC的方式,是不是很简单呢?呵呵!
  • 相关阅读:
    PLSQL Developer连接Oracle11g 64位数据库配置详解
    PL/SQL developer 登录时提示:database character set(AL32UTF8) and Client character set(ZHS16GBK) are different
    例题P101
    疑问
    基本概念
    参数及术语
    使用python 3.x 对pythonchallenge-----17的解答过程
    使用python3 解析html对称标签
    使用python 3.x 对pythonchallenge-----16的解答过程
    使用python 3.x 对pythonchallenge-----15的解答过程
  • 原文地址:https://www.cnblogs.com/stronger-ios-lcx/p/5635492.html
Copyright © 2011-2022 走看看