Skip to content

Instantly share code, notes, and snippets.

View NSNumber+Wrapper.swift
extension NSNumber {
@nonobjc convenience init(_ value: Bool) {
self.init(bool: value)
}
@nonobjc convenience init(_ value: Float) {
self.init(float: value)
}
@nonobjc convenience init(_ value: Double) {
@davbeck
davbeck / assets.rb
Last active Jan 5, 2022
Automatic Enum-based Xcassets in Swift
View assets.rb
#!/usr/bin/env ruby
require "active_support"
def assetCatalogsAtPath(path)
results = []
contents = Dir.entries(path)
@davbeck
davbeck / imgix.md
Created May 16, 2016
imgIX summary
View imgix.md

imgIX

imgIX is similar to a proxy CDN that sits between where we store the full-size images and the devices and browsers that download them. Images are not stored in imgIX directly but instead on an HTTP server such as S3. You configure "sources" in imgIX that then proxy to the source server.

In our case, we would upload images directly to S3, then the clients would request them using the imgIX URL instead of the direct S3 URL. You can then include URL parameters in addition to the original URL that specify the size you will display the images at, the pixel density (ie retina), as well as other transformations such as auto compression. This leads to drastically smaller file sizes, which download faster, use less bandwidth and use less memory on the user's device. There are other features we can take advantage of like smart cropping that centers detail like faces in square cropped photos.

Tests

I uploaded 4 photos from an iPhone 6s to S3 using the app and then tested their dow

View swift-options.md

Swift options

Recently, 2 Swift Evolution proposal results have really disappointed me. Together they move Swift away from the flexibility of using method parameters as option lists.

SE-0060 Enforcing order of defaulted parameters, which was accepted, removes the ability to provide optional parameters in any order you like. I had actually hoped to go the other direction and extend this ability to include required parameters. Now, as you add and remove parameters to a call site, you have to make sure to do so in the proper order. As the number of parameters a method takes grows, and as the relation between them gets weaker, it becomes more and more difficult to determine the correct positioning without referring to documentation.

SE-0084 Allow trailing commas in parameter lists and tuples was rejected. This proposal so

View workflow.md

Workflow

We use Jira to track bugs and features and git flow to track changes to the code. The workflow for a ticket goes as follows:

  1. The developer moves a ticket into the "In Progress" column, assigning it to themselves.

  2. The developer creates a new branch off of develop (or another feature branch if necessary) naming it feature/REALM-XXXXX-description where "REALM-XXXXX" is the ticket number in Jira and "description" is a 1-3 word description of the ticket.

  3. Any changes needed to fulfill the ticket are performed in 1 or more commits. Each commit should start with the ticket number, as in REALM-XXXXX Added link to make a gift. Prefixing the ticket number here causes the commit to appear in Jira.

@davbeck
davbeck / time_zones.swift
Created Jul 29, 2016
Conversion table for Realm to NSTimeZone style names
View time_zones.swift
let realmTimeZoneLookup: [String:String] = [
"Dateline Standard Time": "GMT-1200",
"UTC-11": "GMT-1100",
"Hawaiian Standard Time": "Pacific/Honolulu",
"Alaskan Standard Time": "America/Halifax",
"Pacific Standard Time (Mexico)": "America/Tijuana",
"Pacific Standard Time": "America/Los_Angeles",
"US Mountain Standard Time": "America/Phoenix",
"Mountain Standard Time (Mexico)": "America/La_Paz",
"Mountain Standard Time": "America/Denver",
@davbeck
davbeck / xcode.sh
Created Aug 4, 2016
Xcode switching
View xcode.sh
#!/usr/bin/env bash
rm -rf /Users/davbeck/Library/Developer/Xcode/DerivedData
osascript -e 'quit app "Simulator"'
osascript -e "tell application \"Xcode\"
close every window
end tell"
osascript -e 'quit app "Xcode"'
View moment_tests.js
func testFormatterKit() {
let timeFormatter = TTTTimeIntervalFormatter()
timeFormatter.presentTimeIntervalMargin = 60
timeFormatter.usesIdiomaticDeicticExpressions = true
self.measure {
let timeFormatter = TTTTimeIntervalFormatter()
timeFormatter.presentTimeIntervalMargin = 60
timeFormatter.usesIdiomaticDeicticExpressions = true
View timeline.swift
class TimelineManager<T> {
weak var delegate: TimelineManagerDelegate?
}
protocol TimelineManagerDelegate: class {
func timelineDidLoad<T>(timeline: TimelineManager<T>)
}
View ServerObjectID.swift
//
// ServerObjectID.swift
// Engagement
//
// Created by David Beck on 3/10/17.
// Copyright © 2017 ACS Technologies. All rights reserved.
//
import Foundation
import CoreData