Skip to content

Instantly share code, notes, and snippets.

@masonfmatthews
Created January 27, 2016 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masonfmatthews/20e5b18008c7919e0327 to your computer and use it in GitHub Desktop.
Save masonfmatthews/20e5b18008c7919e0327 to your computer and use it in GitHub Desktop.
Using guard
func getCount() -> Int {
guard let json = self.json else { return 0 }
return json.count
}
func getAll() -> [Clip] {
guard json != nil else { return [] }
var clips:[Clip] = []
for result in json! {
guard let id = result["id"] as? Int,
name = result["name"] as? String,
url = result["url"] as? String else {continue}
clips.append(Clip(id: id, name: name, url: url))
}
return clips
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment