Created
May 18, 2016 06:43
-
-
Save externvoid/931b3efb37090a8d53903101a7492d01 to your computer and use it in GitHub Desktop.
日付リテラルっぽいのを使ってみる。
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 Foundation | |
| var dateFmt: NSDateFormatter = NSDateFormatter() | |
| dateFmt.dateFormat = "yyyy/MM/dd HH:mm:ss" | |
| let date1 = dateFmt.dateFromString("2014/03/18 00:00:00")! | |
| let date2: NSDate = dateFmt.dateFromString("2014/03/19 00:00:00")! | |
| var order = date1.compare(date2) | |
| print(order) | |
| print(order == NSComparisonResult.OrderedDescending) | |
| print(order == NSComparisonResult.OrderedAscending) | |
| print(order.rawValue) | |
| order = date2.compare(date1) | |
| print(order) | |
| print(order.rawValue) | |
| print(NSComparisonResult(rawValue:-1)) | |
| print(NSComparisonResult(rawValue:0)) | |
| print(NSComparisonResult(rawValue: 1)) | |
| var arr: Array<NSNumber> = [10, 2, 4, 17, 1] | |
| var ar = NSMutableArray(array: arr) | |
| print(ar) | |
| ar.sortUsingComparator({ | |
| //ar.sortUsingComparator({(x, y) in | |
| //ar.sortUsingComparator({(x:NSNumber, y:NSNumber) -> NSComparisonResult in | |
| return $1.compare($0 as! NSNumber) | |
| }) | |
| print(ar) | |
| var ar2:Array<NSString> = ["aaa", "bbb", "abc",] | |
| var strings:NSMutableArray = NSMutableArray(array: ar2) | |
| print(strings) | |
| strings.sortUsingComparator( { | |
| return $1.compare($0 as! String) | |
| } ) | |
| print(strings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment