Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am mbogh on github.
  • I am mbogh (https://keybase.io/mbogh) on keybase.
  • I have a public key whose fingerprint is 0ED4 AB00 5EFA BE5D C721 E2BC A96A 3DC5 0FB8 3C8F

To claim this, I am signing this object:

@mbogh
mbogh / wcf.swift
Last active October 29, 2016 13:32
import Foundation
extension NSDate {
convenience init?(WCFDateString dateString: String) {
// First remove nonsense from dateString: /Date(_)/
let dateStringSane = dateString.stringByTrimmingCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)
// Make sure dateStringSane is at least 3 characters
guard dateStringSane.characters.count >= 3 else { return nil }
extension JSONObject {
/// Returns a JSON object initialized by reading into it the data from the file specified by a given path.
/// - Parameter path: The absolute path of the file from which to read data.
/// - Returns: A JSON object initialized by reading into it the data from the file specified by path.
convenience init?(contentsOfFile path: String) {
guard let data = NSData(contentsOfFile: path),
json = (try? NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)) as? [String : AnyObject] else { return nil }
self.init(dictionary: json)
}
}
@mbogh
mbogh / NSObject+setValuesForKeysWithJSONDictionary.h
Created May 3, 2012 13:43 — forked from atomicbird/NSObject+setValuesForKeysWithJSONDictionary.h
NSObject category for handling JSON dictionaries. Described in detail at http://www.cimgf.com/2012/01/11/handling-incoming-json-redux/. Updated to support parent properties.
//
// NSObject+setValuesForKeysWithJSONDictionary.h
// SafeSetDemo
//
// Created by Tom Harrington on 12/29/11.
// Copyright (c) 2011 Atomic Bird, LLC. All rights reserved.
//
#import <Foundation/Foundation.h>