Created
September 25, 2016 22:50
-
-
Save krzyzanowskim/a373a7d68e6808c06d6760d2a834f488 to your computer and use it in GitHub Desktop.
Override Swift function by extension
This file contains 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
// hm... override function implementation. This may be unexpected. | |
public extension String { | |
// wait wait wait... why no error here? | |
// String already have `public func hasPrefix(_ prefix: String) -> Bool` in stdlib | |
// https://github.com/apple/swift/blob/caa173b27a34a26f82a15ccc76cf4d8f95587637/stdlib/public/core/StringLegacy.swift#L143 | |
public func hasPrefix(_ prefix: String) -> Bool { | |
return true // fake it till you make it | |
} | |
} | |
let s = "abcd" | |
if s.hasPrefix("oooo") { | |
print("hasPrefix true") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment