String+Convenience.swift 643 B

1234567891011121314151617181920212223242526
  1. //
  2. // String+Convenience.swift
  3. // Segmentio
  4. //
  5. // Created by Dmitriy Demchenko
  6. // Copyright © 2016 Yalantis Mobile. All rights reserved.
  7. //
  8. import Foundation
  9. extension String {
  10. func stringFromCamelCase() -> String {
  11. var string = self
  12. string = string.replacingOccurrences(
  13. of: "([a-z])([A-Z])",
  14. with: "$1 $2",
  15. options: .regularExpression,
  16. range: nil
  17. )
  18. string.replaceSubrange(startIndex...startIndex, with: String(self[startIndex]))
  19. return String(string.prefix(1)).capitalized + String(string.lowercased().dropFirst())
  20. }
  21. }