0001 // The MIT License (MIT) 0002 // 0003 // Copyright (c) 2015 Suyeol Jeon (xoul.kr) 0004 // 0005 // Permission is hereby granted, free of charge, to any person obtaining a copy 0006 // of this software and associated documentation files (the "Software"), to deal 0007 // in the Software without restriction, including without limitation the rights 0008 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0009 // copies of the Software, and to permit persons to whom the Software is 0010 // furnished to do so, subject to the following conditions: 0011 // 0012 // The above copyright notice and this permission notice shall be included in all 0013 // copies or substantial portions of the Software. 0014 // 0015 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0016 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0017 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0018 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0019 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0020 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0021 // SOFTWARE. 0022 0023 import Foundation 0024 0025 public protocol Then{} 0026 0027 extension Then where Self: Any { 0028 0029 /// Makes it available to set properties with closures just after initializing. 0030 /// 0031 /// let label = UILabel().then { 0032 /// $0.textAlignment = .Center 0033 /// $0.textColor = UIColor.blackColor() 0034 /// $0.text = "Hello, World!" 0035 /// } 0036 public func then(@noescape block: inout Self -> Void) -> Self { 0037 var copy = self 0038 block(©) 0039 return copy 0040 } 0041 0042 } 0043 0044 extension Then where Self: AnyObject { 0045 0046 /// Makes it available to set properties with closures just after initializing. 0047 /// 0048 /// let label = UILabel().then { 0049 /// $0.textAlignment = .Center 0050 /// $0.textColor = UIColor.blackColor() 0051 /// $0.text = "Hello, World!" 0052 /// } 0053 public func then(@noescape block: Self -> Void) -> Self { 0054 block(self) 0055 return self 0056 } 0057 0058 } 0059 0060 extension NSObject: Then {} 0061
Then.swift:27 extension Then where Self: Any {Then.swift:44 extension Then where Self: AnyObject {Then.swift:60 extension NSObject: Then {}