Last active
June 21, 2017 11:11
-
-
Save tsif/57cbb429caa9e616d5502e2868bdb83a to your computer and use it in GitHub Desktop.
Swift 4 & String
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
// collections | |
let filtered = string.filter { $0 != "🙀" } | |
// substrings | |
let substring = string[index...] | |
// multi line literals | |
func printMultiLine() { | |
print( | |
""" | |
Bacon ipsum dolor amet landjaeger chicken. Turkey short ribs ham hock boudin | |
shoulder short loinhank sirloin jerky porchetta. Leberkas filet mignon flank pig capicola tri-tip | |
sausage cupim shankle jowl alcatrha kielbasa meatball shoulder pork chop biltong | |
short loin leberkas rump fturkey boudin pork belly pork chop kevin | |
""" | |
) | |
} | |
// truncation | |
extension String { | |
func truncated() -> Substring { | |
return prefix(truncationLimit) | |
} | |
} | |
// but requires copy on the returned Substring type | |
label.text = String(userInput.truncated()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment