Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Created April 23, 2017 03:57
Show Gist options
  • Save KentarouKanno/69edb46bade2698482b042a65b25558e to your computer and use it in GitHub Desktop.
Save KentarouKanno/69edb46bade2698482b042a65b25558e to your computer and use it in GitHub Desktop.

Optional Extension

★ String?型の変数が空文字だった場合nilを返す
Swift3.1

extension Optional where Wrapped == String {

    func emptyToNil() -> String? {
        if let temp = self,
            temp.isEmpty {
            
            return nil
        } else {
            return self
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment