Last active
August 29, 2015 14:15
-
-
Save ilyapuchka/61b97edbdb8e4aaa1dca 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
protocol HasTitle { | |
var ht_title: String {get set} | |
} | |
extension UIBarButtonItem: HasTitle { | |
var ht_title: String { | |
get { | |
return self.title ?? "" | |
} | |
set { | |
self.title = newValue | |
} | |
} | |
} | |
extension UIMenuItem: HasTitle { | |
var ht_title: String { | |
get { | |
return self.title | |
} | |
set { | |
self.title = newValue | |
} | |
} | |
} | |
let button = UIBarButtonItem(title: "a", style: UIBarButtonItemStyle.Plain, target: nil, action: "action") | |
let menu = UIMenuItem(title: "b", action: "action") | |
let array: [HasTitle] = [button, menu] | |
//without () compiler thinks that's closure 'cause we have 'in' | |
for (var item) in array { | |
item.ht_title = item.ht_title.uppercaseString | |
} | |
for item in a { | |
println(item.ht_title) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment