Created
January 11, 2018 10:15
-
-
Save SergeyPetrachkov/f56d5af89fd62ccc84124ded653db513 to your computer and use it in GitHub Desktop.
Get string initials 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
| extension String { | |
| public var initials: String { | |
| var finalString = String() | |
| var words = components(separatedBy: .whitespacesAndNewlines) | |
| if let firstCharacter = words.first?.first { | |
| finalString.append(String(firstCharacter)) | |
| words.removeFirst() | |
| } | |
| if let lastCharacter = words.last?.first { | |
| finalString.append(String(lastCharacter)) | |
| } | |
| return finalString.uppercased() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment