Skip to content

Instantly share code, notes, and snippets.

View MacMeDan's full-sized avatar

Dan Leonard MacMeDan

View GitHub Profile

Keybase proof

I hereby claim:

  • I am macmedan on github.
  • I am macmedan (https://keybase.io/macmedan) on keybase.
  • I have a public key ASBmUfgfucVoU0MNe7QCDNrzAxCLCJZ-qq9NNs1uM2I4Igo

To claim this, I am signing this object:

@MacMeDan
MacMeDan / camelCased.swift
Last active March 6, 2018 18:59
Take a string and make a camelCased version of it.
extension String {
// created by - Dan Leonard 3/6/2018
// https://gist.github.com/MacMeDan/491fbe1361bafaa009adce6bf549f5d5
/// lowercased to start and Capitalised each segment that fallows.
/// if there are more then 10 words in the sentence
var camelCased: String {
var componets = self.components(separatedBy: " ")
guard let first = componets.first?.lowercased() else { fatalError("Invalid string for enum generation") }
if componets.count == 1 { return "\(first)"}
let rest = componets.dropFirst().flatMap{ $0.capitalized }.joined()
@MacMeDan
MacMeDan / validChars.swift
Last active March 6, 2018 18:58
String extension that filters out invalid characters for enum case names.
extension String {
// created by - Dan Leonard 3/6/2018
// https://gist.github.com/MacMeDan/ef9e49dfbab19f084da5cb43d48a77b0
// NOTE: does not account for individual numbers
var validChars: String {
return String(describing: filter { String($0).rangeOfCharacter(from: .alphanumerics) != nil })
}
}