New @convention(c) in Swift 2: How can I use it?

Passing a Swift closure to a C function taking a function pointer parameter is now supported in Swift 2, and, as you noticed, function types are specified with the @convention(c) attribute. If you pass a closure directly as an argument to the C function then this attribute is inferred automatically. As a simple example, if … Read more

Swift 2.0 Sorting Array of Objects by Property

In Swift 2: You can use sort method, using compare to compare the two dates: let sortedArray = myArray.sort { $0.myDate.compare($1.myDate) == .OrderedAscending } // use `sorted` in Swift 1.2 Or, if you want to sort the original array, you can sortInPlace: myArray.sortInPlace { $0.myDate.compare($1.myDate) == .OrderedAscending } // use `sort` in Swift 1.2 In … Read more

Swift debugger does not show variable values when importing ObjC framework

I got a message from an Apple developer stating that they’ve observed this problem, and that it could be fixed by moving the .framework to a subfolder of the project. Apparently the module .. was built in directory error appears only if the .framework is in the same folder as the .xcodeproj aka $(PROJECT_DIR). However … Read more

Fix warning “C-style for Statement is deprecated” in Swift 3

C-style for loop has been deprecated in Swift 3. You can continue using it for a while, but they will certainly disappear in the future. You can rewrite your loop to Swift’s style: for i in 0..<len { let length = UInt32 (letters.length) let rand = arc4random_uniform(length) randomString.appendFormat(“%C”, letters.characterAtIndex(Int(rand))) } Since you don’t use i … Read more