Created
August 31, 2015 02:06
-
-
Save JessyCatterwaul/75242c8b6a883f416d8b to your computer and use it in GitHub Desktop.
Property initalizers in Swift
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
// It would help if Xcode visually differentiated between verbs and deverbal nouns. | |
// It can get a little confusing using a human brain to parse which of those options each meow is. | |
class Cat { | |
init(meow: String = "Meow.") { | |
// How this might look in Swift in the future. | |
// self.meow.init(meow: meow) | |
// How I have been emulating that | |
// Pronounce 🐣 as "hatch" to understand its purpose. | |
self.meow = Cat.🐣meow(meow: meow) | |
// MARK: meow | |
// meow = ... | |
} | |
// How this might look in Swift in the future. | |
// Note that this requires two features: | |
// 1. external parameter names for closures | |
// 2. property initializers | |
// let meow: (forSome thing: LikableThing) -> () | |
// meow.init(meow: String) {return { | |
// switch thing { | |
// case .food: print(meow, meow) | |
// case .moreFood: print(meow, meow, meow) | |
// case .pets: print(meow) | |
// } | |
// }} | |
// How I have been emulating that | |
let meow: (forSome: LikableThing) -> () | |
private static func 🐣meow(meow meow: String) -> | |
LikableThing -> () { | |
func meow(forSome thing: LikableThing) { | |
switch thing { | |
case .food: print(meow, meow) | |
case .moreFood: print(meow, meow, meow) | |
case .pets: print(meow) | |
} | |
}; return meow} | |
} | |
extension Cat {enum LikableThing { | |
case food, moreFood, pets | |
}} | |
Cat().meow(forSome: .food) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment