Skip to content

Instantly share code, notes, and snippets.

View sberrevoets's full-sized avatar

Scott Berrevoets sberrevoets

View GitHub Profile
final class Storage<StoredValue> {
private var storage: [StoredValue] = []
func addFailingValue<T: ModelRepresentable>(_ model: T) where T.Model == StoredValue {
self.storage.append(model.value)
}
func addValue<T: ModelRepresentable>(_ model: T) {
guard let value = model.value as? StoredValue else { return }
self.storage.append(value)
[
{
"date": {
"duration": 244799,
"start": 1522900800
},
"id": "rwdevcon-2018",
"name": "RWDevCon 2019",
"sessions": [
{
@sberrevoets
sberrevoets / timezone.swift
Created July 13, 2016 21:33
Changing NSDateFormatter's time zone
let formatter = NSDateFormatter()
formatter.dateStyle = .NoStyle
formatter.timeStyle = .FullStyle
formatter.timeZone = NSTimeZone(name: "America/Los_Angeles")
print("1 \(formatter.stringFromDate(NSDate()))")
formatter.timeZone = NSTimeZone(name: "America/Chicago")
print("2 \(formatter.stringFromDate(NSDate()))")
@sberrevoets
sberrevoets / SDCIntrinsicallySizedView
Last active August 29, 2015 13:56
UIView subclass that has a valid intrinsicContentSize based on its subviews' frames
- (CGSize)intrinsicContentSize {
__block CGFloat minX = CGFLOAT_MAX;
__block CGFloat maxX = CGFLOAT_MIN;
__block CGFloat minY = CGFLOAT_MAX;
__block CGFloat maxY = CGFLOAT_MIN;
[[self subviews] enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) {
// Ignore _UILayoutGuide
if (![subview conformsToProtocol:@protocol(UILayoutSupport)]) {
// We could use CGRectGet(Min|Max)(X|Y) using the subview.frame, but subview.frame is undefined when a transform is applied. This calculation is transform-friendly.