This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| func sizeHeightWithText(labelText: String, | |
| fontSize: CGFloat, | |
| textAttributes: [String : AnyObject]) -> CGRect { | |
| return labelText.boundingRect( | |
| with: CGSize(width:fontSize, height:480), | |
| options: NSStringDrawingOptions.usesLineFragmentOrigin, | |
| attributes: textAttributes, context: nil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let fontSize: CGFloat = 22.0 | |
| func sizeHeightWithText(labelText: NSString, | |
| fontSize: CGFloat, | |
| textAttributes: [String : Any]) -> CGRect { | |
| return labelText.boundingRect( | |
| with: CGSize(width:fontSize, height:480), | |
| options: NSStringDrawingOptions.usesLineFragmentOrigin, | |
| attributes: textAttributes, context: nil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func swapTwoValues<Joseph>(_ a: inout Joseph, _ b: inout Joseph) { | |
| let temporaryA = a | |
| a = b | |
| b = temporaryA | |
| } | |
| var someInt = 3 | |
| var anotherInt = 107 | |
| swapTwoValues(&someInt, &anotherInt) | |
| print("someInt 现在是\(someInt),anotherInt 现在是 \(anotherInt)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func swapTwoInts(_ a: inout Int, _ b: inout Int) { | |
| let temporaryA = a | |
| a = b | |
| b = temporaryA | |
| } | |
| var someInt = 3 | |
| var anotherInt = 107 | |
| swapTwoInts(&someInt, &anotherInt) | |
| print("someInt 现在是 \(someInt),anotherInt 现在是 \(anotherInt)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol ManagedObjectContextSettable: class { | |
| var managedObjectContext: NSManagedObjectContext! { get set } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let nickName: String? = nil | |
| let fullName: String = "John Appleseed" | |
| let informalGreeting = "Hi \(nickName ?? fullName)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func objectAtIndexPath(indexPath: NSIndexPath) -> Object { | |
| guard let result = fetchedResultsController.objectAtIndexPath(indexPath) | |
| as? Object else | |
| { | |
| fatalError("Unexpected object at \(indexPath)") | |
| } | |
| return result | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -(void) callMe { | |
| //... | |
| } | |
| -(void) callMeWithParam:(id)obj { | |
| //... | |
| } | |
| SEL someMethod = @selector(callMe); | |
| SEL anotherMethod = @selector(callMeWithParam:); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func addTo(_ adder: Int) -> (Int) -> Int { | |
| return { | |
| num in | |
| return num + adder | |
| } | |
| } | |
| let addTwo = addTo(2) //addTwo:Int -> Int | |
| let result = addTwo(6) //result = 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| // 在这里销毁所有可以被重建的资源 | |
| } |