Skip to content

Instantly share code, notes, and snippets.

@JaviSoto
JaviSoto / swiftlint.yml
Created Jun 16, 2020
disallowed_racist_terms_of_art SwiftLint
View swiftlint.yml
disallowed_racist_terms_of_art:
name: "Disallowed racist terms of art"
regex: 'blacklist|whitelist|^((?<!git)[^\n])*master(?! (manifest|playlist))|slave'
message: "Please, refrain from using terms which have racist connotations. Consider alternatives such as allow, disallow, primary, secondary..."
severity: error
@JaviSoto
JaviSoto / UIView+TWSafeAreaInsets.swift
Last active Apr 14, 2020
Status-bar agnostic UIView.safeAreaInsets API
View UIView+TWSafeAreaInsets.swift
extension UIView {
/// Convenience API to query iOS 11's `UIView.safeAreaInsets`'s insets (also known as "#NotEmbraceTheNotch")
/// in a backwards compatible API.
/// It also differs slightly from `UIView.safeAreaInsets` in that it only takes the "Notch" into account
/// and not the status bar. This allows you to inset content so that the notch doesn't clip it, but you can still
/// lay it out below the status bar.
/// Note: This won't be as versitile as the UIKit version because it won't take into account things like navigation bars,
/// but it should be correct for views in "full-screen" view controllers, where the UIKit `safeAreaInsets` API falls short.
var twSafeAreaInsets: UIEdgeInsets {
guard #available(iOS 11.0, *) else {
@JaviSoto
JaviSoto / wwdc16.md
Created Jul 15, 2016 — forked from mackuba/wwdc16.md
New stuff from WWDC 2016
View wwdc16.md

Following the tradition from last year, here's my complete list of all interesting features and updates I could find in Apple's OSes, SDKs and developer tools that were announced at this year's WWDC. This is based on the keynotes, the "What's New In ..." presentations and some others, Apple's release notes, and blog posts and tweets that I came across in the last few weeks.

If for some reason you haven't watched the talks yet, I really recommend watching at least the "State of the Union" and the "What's New In" intros for the platforms you're interested in. The unofficial WWDC Mac app is great way to download the videos and keep track of what you've already watched.

If you're interested, here are my WWDC 2015 notes (might be useful if you're planning to drop support for iOS 8 now and start using some iOS 9 APIs).


OSX → macOS 10.12 Sierra

@JaviSoto
JaviSoto / NibInstantiable.swift
Last active Apr 14, 2020
RSwift Fabric Extensions
View NibInstantiable.swift
import UIKit
import Rswift
struct NibResource: NibResourceType {
let name: String
let bundle: NSBundle
init(name: String, bundle: NSBundle = NSBundle.mainBundle()) {
self.name = name
self.bundle = bundle
@JaviSoto
JaviSoto / Example.swift
Last active Jul 17, 2017
TableSectionDataDiffing
View Example.swift
var sections: [MySectionType] {
didSet {
let operations = TableSectionDataDiffing.tableOperationsToUpdateFromSections(sections: oldValue, toSections: sections)
self.tableView.applyTableOperations(operations, withAnimations: updateAnimations)}
}
}
View RAC+logEvents.swift
public enum ReactiveCocoaEventType {
case Started
case Next
case Completed
case Failed
case Terminated
case Disposed
case Interrupted
public static let allEvents: Set<ReactiveCocoaEventType> = {
View DataLoadState.swift
//
// DataLoadState.swift
// Fabric
//
// Created by Javier Soto on 3/16/16.
// Copyright © 2016 Fabric. All rights reserved.
//
import Foundation
import ReactiveCocoa
@JaviSoto
JaviSoto / SampleViewController.swift
Last active Jan 23, 2020
Init based Storyboard View Controller Instantiation
View SampleViewController.swift
final class SampleViewController: StoryboardBackedViewController {
// Unfortunately this must be an IUO var, so that we can set the value after super.init
private var member: Foo!
// Proper dependency injection in a storyboard backed VC!
init(foo: Foo) {
super.init(storyboardIdentifier: "SampleViewControllerIdentifier")
// We have to set the members *after* calling super.init, since it changes the instance of `self`.
self.member = foo
View swift-self-build
#!/bin/bash
set -e
trap "exit;" SIGINT SIGTERM
unset TOOLCHAINS
ALIAS=mxcl
VERSION="3.0.0-${ALIAS}+$(date +%Y%m%d)"
PREFIX="$HOME/Library/Developer/Toolchains"
View gist:11dd06b06a94343cbfe6
Your goals are to reduce the number of things that you have to keep in your head at any given moment, and to rely as little as possible on your own ability to consistently do things right.
If you make a thing immutable ('let' in swift), you never have to think about what happens if it changes, or what other parts of the code you'll effect if you change it.
If you split complex functions into several smaller functions that only interact by passing arguments or getting return values, then you limit the amount of code you need to consider when hunting for a bug, and you can test each small piece separately.
If you understand what things must be true in your code (aka invariants, for example "a person's age must be greater than 0"), and either provide no function that can cause them to be untrue, or check and crash immediately when they're untrue, then you don't have to debug issues caused by incorrect assumptions.
If you remove possibilities (for example, Swift removes the possibility of things being nil unless
You can’t perform that action at this time.