Skip to content

Instantly share code, notes, and snippets.

View scott-lydon's full-sized avatar

Scott scott-lydon

  • High Five
  • Burlingame
View GitHub Profile
@scott-lydon
scott-lydon / ForceUnwrap.md
Last active January 10, 2022 19:39
Unwrap methods: force.

Alternative 1: Force unwrap non-optional dependencies

PROs:

  • No need no use any methods to unwrap on each usage, unless there are cases you anticipate a value to be nil.
var value: String!
value = "Hi"
print(value.count) 
Pod::Spec.new do |s|
s.name = "BlaBlabla"
s.version = "0.1.0"
s.summary = "Description of your project"
s.description = "Mandatorily longer description of your project"
s.homepage = "https://github.com/ElevatedUnderdogs/PracticeCocoaPod1/tree/main"
s.license = "Description of your licence, name or otherwise"
s.author = { "Developer" => "[email protected]" }
s.platform = :ios, "9.0"
@scott-lydon
scott-lydon / RaceCondition.swift
Created June 25, 2021 01:28
A playground demo to demonstrate a common race condition
import UIKit
public extension DateFormatter {
static let iso8601withFractionalSeconds: DateFormatter = {
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .iso8601)
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
@scott-lydon
scott-lydon / Alternative.swift
Created May 4, 2021 21:02
private setting variables.
struct CreateAccountViewModel {
var image: Image
var accentText: String
var choosePathVM: ChoosePathViewModel {
didSet {
self.currentHeader = choosePathVM.current
self.employeeDestination = choosePathVM.current.header == HeaderBody.employee.header
self.authViewModel = employeeDestination ? .employeeForm : .businessForm
self.formModel = employeeDestination ? .employee : .business
struct CreateAccountViewModel {
var image: Image = Image("IntroImage")
var accentText: String = "Choose Account type"
var choosePathVM: ChoosePathViewModel = ChoosePathViewModel(index: 0, explanations: [.employee, .business])
var buttonImage: Image = Image(systemName: .rightArrowLine)
var spacerHeight: CGFloat = 40
var currentHeader: HeaderBody {
get {
choosePathVM.current
struct CreateAccountViewModel {
var image: Image = Image("IntroImage")
var accentText: String = "Choose Account type"
var choosePathVM: ChoosePathViewModel = ChoosePathViewModel(index: 0, explanations: [.employee, .business])
var buttonImage: Image = Image(systemName: .rightArrowLine)
var spacerHeight: CGFloat = 40
func sendHeader() { headerAction?(choosePathVM.current) }
var currentHeader: HeaderBody { choosePathVM.current }
var employeeDestination: Bool { choosePathVM.current.header == HeaderBody.employee.header }
var formModel: SignupFormViewModel { employeeDestination ? .employee : .business}
// Shared types/interfaces between Java and Swift
package com.johnholdsworth.swiftbindings;
import java.util.HashMap;
public interface SwiftHelloTypes {
// An example of publishing an object to Java.
// Add the associated protocol to an class and
// objects can be passed to a responder message.
public interface TextListener {
public String getText();
package com.johnholdsworth.swiftbindings;
import com.johnholdsworth.swiftbindings.SwiftHelloTypes.TextListener;
import com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMap;
import com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMapList;
public interface SwiftHelloBinding {
// Messages from JavaActivity to Swift
public interface Listener {
public void setCacheDir( String cacheDir );
public void processNumber( double number );
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://url/of/another/package.git", from: "1.0.0"),
.package(path: "path/to/a/local/package/", "1.0.0"..<"2.0.0")],
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "MyLibrary",
platforms: [
.macOS(.v10_14), .iOS(.v13), .tvOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.