Skip to content

Instantly share code, notes, and snippets.

@chosa91
chosa91 / Publisher+extension.swift
Created September 27, 2021 16:30
Publisher extension
import Combine
extension Publisher {
func withInitialValue(_ value: Output) -> AnyPublisher<Output, Failure> {
merge(with: Just(value).setFailureType(to: Failure.self)).eraseToAnyPublisher()
}
}
@chosa91
chosa91 / DictionaryTupleDecoder.swift
Last active April 20, 2021 08:07
Destructure dictionaries into tuple
// Source: https://twitter.com/NSExceptional/status/1383665312684335105
// MARK: - Helpers
extension UnsafePointer {
var raw: UnsafeRawPointer {
return UnsafeRawPointer(self)
}
@chosa91
chosa91 / hackweek_2021_q1.md
Last active March 12, 2021 09:59
The week of practicing #fail-early & #fail-often

The week of practicing "#fail-early" & "#fail-often"

Main-plan: Fullstory iOS Integration

TL;DR

PRO plan not pro enough (doesn't include the mobile add-on)

But... the technical support is quick and helpful.

@chosa91
chosa91 / GridViewController.swift
Last active November 24, 2020 11:55
Stackoverflow question: UICollectionViewCompositionalLayout multi column layout with auto-sizing cells - https://stackoverflow.com/a/64985964/2569338
/*
GOAL:
- UICollectionViewCompositionalLayout multi column layout with auto-sizing cells where each cell has the same height in a given row (uses the max cell height in a row)
REALITY:
- The groups aren't filled :/
*/
import Foundation
import UIKit
@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)
import UIKit
// Source: https://sarunw.com/posts/match-view-shadow-to-sketch-shadow/
extension UIView {
func applySketchShadow(
color: UIColor = .black,
alpha: Float = 0.2,
x: CGFloat = 0,
y: CGFloat = 2,
@chosa91
chosa91 / Published.swift
Last active May 15, 2020 11:09
Backward compatible reactive ObservableObject
import Foundation
import UIKit
// Source: https://www.swiftbysundell.com/articles/published-properties-in-swift/
// MARK: - List
struct List<Value> {
private(set) var firstNode: Node?
private(set) var lastNode: Node?
@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