Skip to content

Instantly share code, notes, and snippets.

@marcpalmer
Last active August 29, 2015 14:08
Show Gist options
  • Save marcpalmer/b1fc694ce398c82e614f to your computer and use it in GitHub Desktop.
Save marcpalmer/b1fc694ce398c82e614f to your computer and use it in GitHub Desktop.
Obscure bug with > overloading with UIKit under iOS
// This code fails to compile with iOS SDK 8.1 and Xcode 6.1
import UIKit
let names = ["a","c","b"]
// This fails to compile on iOS targets
// It works if:
// a) you add "return" to the closure
// - or -
// b) you remove the UIKit import
var reversed = sorted(names) { $0 > $1 }
println(reversed)
@marcpalmer
Copy link
Author

Notes:

  • Using < operator works fine
  • It seems impossible to find out where the declaration of ">" is coming from and hence what is wrong. Can Xcode help us solve problems like this or not?

@marcpalmer
Copy link
Author

I think the problem is that there are declarations for:

func <(lhs: UnicodeScalar, rhs: UnicodeScalar) -> Bool
func <(lhs: UInt, rhs: UInt) -> Bool
func <(lhs: String.Index, rhs: String.Index) -> Bool
func <(lhs: String, rhs: String) -> Bool

...but no such overrides declared for >

@marcpalmer
Copy link
Author

Although this doesn't make sense to me, how adding "return" can fix the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment