Skip to content

Instantly share code, notes, and snippets.

@brocoo
Created July 23, 2015 11:34
Show Gist options
  • Select an option

  • Save brocoo/a193c03bf3c1d3480106 to your computer and use it in GitHub Desktop.

Select an option

Save brocoo/a193c03bf3c1d3480106 to your computer and use it in GitHub Desktop.

Revisions

  1. brocoo created this gist Jul 23, 2015.
    13 changes: 13 additions & 0 deletions Extensions.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    // MARK: - NSUserDefaults

    extension NSUserDefaults {

    class func performOnceForKey(key: String, perform: () -> Void, elsePerform: (() -> Void)? = nil) {
    let once = self.standardUserDefaults().objectForKey(key)
    self.standardUserDefaults().setBool(true, forKey: key)
    self.standardUserDefaults().synchronize()

    if once == nil { perform() }
    else { elsePerform?() }
    }
    }