Skip to content

Instantly share code, notes, and snippets.

@ilyapuchka
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyapuchka/61b97edbdb8e4aaa1dca to your computer and use it in GitHub Desktop.
Save ilyapuchka/61b97edbdb8e4aaa1dca to your computer and use it in GitHub Desktop.
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