Skip to content

Instantly share code, notes, and snippets.

@chosa91
chosa91 / Best in Class iOS Checklist
Created August 29, 2020 11:52 — forked from DreamingInBinary/Best in Class iOS Checklist
This is a public checklist updated every year after the latest version of iOS and iPadOS are shipped. It's a boiled down version of a "Best in Class" app checklist created by Jordan Morgan.
# A Best in Class Checklist
A boiled down checklist adapted from this [post](https://www.swiftjectivec.com/a-best-in-class-app/), created by @jordanmorgan10.
> To use this, create a Github Issue in your own repo, and simply copy and paste this text.
## iOS Core Technology
_Things any iOS app can benefit from_
- [ ] iCloud Sync
- [ ] [Core Spotlight integration](https://github.com/DreamingInBinary/Spend-Stack/issues/120)
@chosa91
chosa91 / FileManagerExtensions.swift
Created April 17, 2020 12:27 — forked from AvdLee/FileManagerExtensions.swift
Easily print out useful locations for usage during debugging on the Simulator.
extension FileManager {
/*
Prints out the locations of the simulator and the shared group folder.
This is useful for debugging file issues.
Example usage: FileManager.default.printFileLocations()
*/
func printFileLocations() {
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let simulatorFolder = paths.last!
@chosa91
chosa91 / updateSafeAreaForKeyboardFromNotification.swift
Created March 20, 2020 14:21 — forked from douglashill/updateSafeAreaForKeyboardFromNotification.swift
Avoid the keyboard by leveraging additionalSafeAreaInsets.
// Avoids the keyboard in a UIKit app by leveraging additionalSafeAreaInsets.
// You can put this in the root view controller so the whole app will avoid the keyboard.
// Only tested on iOS 13.3.
// Made for https://douglashill.co/reading-app/
@objc func updateSafeAreaForKeyboardFromNotification(_ notification: Notification) {
guard let endFrameInScreenCoords = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else {
return
}
// Please consider whether the force unwrap here is safe for your own use case.
@discardableResult
public func with<T>(_ value: T, _ builder: (T) -> Void) -> T {
builder(value)
return value
}
@discardableResult
public func with<T>(_ value: T, _ builder: (T) throws -> Void ) rethrows -> T {
try builder(value)
return value
struct StateMachine<State, Action> {
private(set) var state: State
private let transition: (State, Action) -> State?
init(startState: State, transition: @escaping (State, Action) -> State?) {
self.state = startState
self.transition = transition
}
mutating func apply(action: Action) -> Bool {
@chosa91
chosa91 / libdispatch-efficiency-tips.md
Created February 22, 2020 14:55 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

I suspect most developers are using the libdispatch inefficiently due to the way it was presented to us at the time it was introduced and for many years after that, and due to the confusing documentation and API. I realized this after reading the 'concurrency' discussion on the swift-evolution mailing-list, in particular the messages from Pierre Habouzit (who is the libdispatch maintainer at Apple) are quite enlightening (and you can also find many tweets from him on the subject).

My take-aways are:

@chosa91
chosa91 / AutoLayout.md
Created February 8, 2020 09:53 — forked from oliverkrakora/AutoLayout.md
The best damn AutoLayout guide I've ever seen

ℹ️ This article is also available on his blog.


Fundamentals

Layout and Drawing are two different things:

  • Layout defines only the positions and sizes of all views on screen.
  • Drawing specifies how each view is rendered (how it looks).
@chosa91
chosa91 / GivenWhenThen.swift
Created January 13, 2020 17:29 — forked from IanKeen/GivenWhenThen.swift
FunctionBuilder mvp for a given/when/then test setup
import XCTest
@_functionBuilder
struct Test<T> {
var data: T
var given: given<T>
var when: when<T>
var then: then<T>
func execute() {
@chosa91
chosa91 / KeyboardScrollView.swift
Created December 2, 2019 05:56 — forked from douglashill/KeyboardScrollView.swift
A UIScrollView subclass that allows scrolling using a hardware keyboard like NSScrollView. Supports arrow keys, option + arrow keys, command + arrow keys, space bar, page up, page down, home and end.
// Douglas Hill, November 2019
import UIKit
/// A scroll view that allows scrolling using a hardware keyboard like `NSScrollView`.
/// Supports arrow keys, option + arrow keys, command + arrow keys, space bar, page up, page down, home and end.
/// Limitations:
/// - Paging scroll views (isPagingEnabled = true) are not supported yet.
/// - The scroll view must become its own delegate so setting the delegate is not supported yet.
/// - Does not consider zooming. This has not been tested at all.
import Foundation
struct AnyEquatable {
private let isEqualTo: (Any) -> Bool
let value: Any
init<A: Equatable>(_ value: A) {
self.value = value
isEqualTo = { other in
guard let o = other as? A else { return false }