Skip to content

Instantly share code, notes, and snippets.

View sambhav7890's full-sized avatar

Sambhav Shah sambhav7890

  • IDfy
  • Mumbai, India
  • 20:07 (UTC +05:30)
View GitHub Profile
@sambhav7890
sambhav7890 / CodableHelperExtensions.swift
Created December 5, 2017 10:32
Helper Extensions For Codable Protocol
/*
Use with Dictionary data
let object:DecodableType? = DecodableType.create(dictionaryData)
*/
extension Decodable {
static func create(object: Any) -> Self? {
guard let dataDict = object as? [String: Any] else { return nil }
@sambhav7890
sambhav7890 / ManagedCodableProtocol.swift
Created November 27, 2017 13:04
Codable Compatibility for NSManagedObjects
/*
//Extended Protocol which allows decoding NSManagedObjects using swift4 Codable Protocol.
//Requires the convenience initializer implementation as follows
public final class City: NSManagedObject, ManagedObjectCodable {
convenience public init(from decoder: Decoder) throws {
// Get Context from decoder
guard let context = decoder.userInfo[.context] as? NSManagedObjectContext else { fatalError("No Managed Object Context!") }
func quicksort<T: Comparable>(var list: T[]) -> T[] {
if list.count <= 1 {
return list
}
let pivot = list[0]
var smallerList = T[]()
var equalList = T[]()
var biggerList = T[]()