Created
July 21, 2016 10:15
-
-
Save artemkrachulov/3c271cb7c813bf453a70a506910d355b to your computer and use it in GitHub Desktop.
Uppercase first character for represented 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
// | |
// String+Case.swift | |
// | |
// Created by Artem Krachulov | |
// Copyright (c) 2016 Artem Krachulov. All rights reserved. | |
// http://www.artemkrachulov.com | |
// | |
import UIKit | |
extension String { | |
/// Uppercase first character for represented string. | |
/// | |
/// Usage: | |
/// | |
/// "hello, world".uppercaseFirst // "Hello, world" | |
/// "".uppercaseFirst // "" | |
public var uppercaseFirst: String { | |
guard !isEmpty else { return "" } | |
var text = self | |
text.replaceRange(text.startIndex...text.startIndex, with: String(text[text.startIndex]).capitalizedString) | |
return text | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment