标签:
一:@autoclosure将一段代码块活着一句表达式自动的封装成一个闭包
func logIfTrue(predicate: () -> Bool) { if predicate() {
print("True")
}
}
调用
在predicate加上@autoclosure调用的时候就可以省略{}直接使用logIfTrue(2>1)
二:??的定义:
三:闭包:
四:操作符重载:
五:错误-Operator implementation without matching operator declaration
因为没有对操作符进行声明
六 :NSAutoreleasePool实现
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
七:关于懒加载:
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 }
你可以这样简单的实现
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 }()
textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
标签:
原文地址:http://www.cnblogs.com/stronger-ios-lcx/p/5635492.html