Skip to content

Instantly share code, notes, and snippets.

@staminajim
staminajim / LegacyInt2CodableExample.swift
Created April 26, 2019 06:22
A strategy for dealing with structs that have been made Codable in a Swift update, but clash with your existing implementation
/*
Example of a way to read in serialized data (eg. json) when Swift adds built in
Codable / Hashable / Equatible to a struct / class that previously didn't, yet they decided
to serialize things differently than you did in existing code.
In this example, I had previously serialized int2 to a dictionary with x and y keys for its
x and y properties. Swift 5 serializes this as an array, which is incompatible and causes
the whole json file to fail to deserialize.
You could write a custom init(from decoder: Decoder for each class using the problematic struct,
@staminajim
staminajim / DispatchQueue+Dedupe.swift
Created January 8, 2019 11:47
Simple CGD Based Debouncing / Deduping
// Copyright (c) 2019, SeatGeek, Inc
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
### Keybase proof
I hereby claim:
* I am staminajim on github.
* I am staminajim (https://keybase.io/staminajim) on keybase.
* I have a public key ASBzCQ6AHVAt3IeW03YpAjRGjhT6TovpFvfxXlVuMomzwgo
To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am staminajim on github.
  • I am staminajim (https://keybase.io/staminajim) on keybase.
  • I have a public key ASC3LOlVEGJEO4coiJxOlPhG0YbLf6UX05v4kUO6iO6E3Qo

To claim this, I am signing this object: