Skip to content

Instantly share code, notes, and snippets.

View closer27's full-sized avatar

Seungwon Kim closer27

View GitHub Profile
@closer27
closer27 / Swift JSON Playground
Last active November 2, 2017 14:37 — forked from benrigas/Swift JSON Playground
Swift4 Playground for initializing objects from Dictionary/JSON
// Playground - noun: a place where people can play
import Cocoa
extension String {
func dictionaryFromJSON () -> Dictionary<String, AnyObject>? {
do {
if let data = self.data(using: .utf8), let dict = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as? [String: AnyObject] {
return dict
}