Created
August 5, 2019 07:51
-
-
Save vibinnair/51e95bdbe180af2d07f3ceca522250d7 to your computer and use it in GitHub Desktop.
Functional Swift: Retreive all hashtags from a 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
//Ref: https://www.swiftbysundell.com/basics/map-flatmap-and-compactmap | |
import Foundation | |
func hashTags(from string: String) -> [String] { | |
return string.components(separatedBy: .whitespacesAndNewlines) | |
.filter {string in string.starts(with: "#")} | |
} | |
print(hashTags(from: "#WWDC 2019 was #awesome #greatday")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment