Skip to content

Instantly share code, notes, and snippets.

@mbrowne
mbrowne / TransferMoney.swift
Last active November 4, 2024 05:00
DCI in Swift - simple money transfer example
//TransferMoney context
class TransferMoney: Context {
private let SourceAccount: SourceAccountRole
private let DestinationAccount: DestinationAccountRole
init(source:AccountData, destination:AccountData) {
SourceAccount = source as! SourceAccountRole
DestinationAccount = destination as! DestinationAccountRole
@oleander
oleander / Makefile
Created April 6, 2017 12:26
How to use the Swift Package Manager and CocoaPods within the same XCode application
APP="MyApp"
CONSTRUCT=xcodebuild -workspace $(APP).xcworkspace -scheme $(APP) clean
install_deps:
pod install
create_config:
swift package fetch
swift package generate-xcodeproj
wipe:
rm -rf .build $(APP).xcodeproj $(APP).xcworkspace Package.pins Pods Podfile.lock
@yossan
yossan / io_monad_sample.swift
Last active September 19, 2019 08:36
IO Monad with Swift
enum Pair<T, WORLD> {
case cons (T, WORLD) // (value, outside)
}
// Outside the computer
typealias WORLD = Any
// IO Monad Instance (a.k.a IO Action)
typealias IO<T> = (WORLD) -> Pair<T, WORLD>
@BjornRuud
BjornRuud / UILabel+Debug.swift
Created November 7, 2017 12:09
Debug mode for UILabel that can optionally show bounds, ascender, descender, x height, cap height, baseline and leading.
import UIKit
struct UILabelDebugOptions: OptionSet {
let rawValue: Int
static let bounds = UILabelDebugOptions(rawValue: 1 << 0)
static let ascender = UILabelDebugOptions(rawValue: 1 << 1)
static let descender = UILabelDebugOptions(rawValue: 1 << 2)
static let xHeight = UILabelDebugOptions(rawValue: 1 << 3)
static let capHeight = UILabelDebugOptions(rawValue: 1 << 4)
@harrytwright
harrytwright / Predicatable.swift
Last active April 30, 2022 13:01
Swift4 KeyPath Predicate
import Foundation
/// Predicatable is the protocol that all predicting objects conform.
public protocol Predicatable: CustomStringConvertible {
/// Returns a Boolean value indicating whether the specified object matches the conditions specified by the predicate.
///
/// - Parameter object: The object against which to evaluate the predicate.
/// - Returns: `true` if object matches the conditions specified by the predicate, otherwise `false`.
func evaluate(with object: Any?) -> Bool
@arturgrigor
arturgrigor / Podfile
Created September 10, 2018 09:55
Sample Podfile for silencing warnings for CocoaPods dependencies
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target '%TargetName%' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for %TargetName%
# pod 'FBSDKCoreKit'
end
//
// ContentView.swift
// TestingMoreSwiftUI
//
// Created by Chris Eidhof on 04.06.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
import Combine
struct LazyView<Content: View>: View {
let build: () -> Content
init(_ build: @autoclosure @escaping () -> Content) {
self.build = build
}
var body: Content {
build()
}
}
@Cortado-J
Cortado-J / LazyStream.swift
Last active August 10, 2020 04:49
Enables simple refactoring of lazy processing of 'streams' of values.
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
///<<< Support Code for Lazy Streams
///<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
///
/// Enables simple refactoring of lazy processing of 'streams' of values.
/// A stream is taken here ot mean a lazy sequence.
///
/// The code is not generic so if streams of different types are required
/// then extra sctions will be needed.
/// Simple to construct for a new type T though:
@mattt
mattt / main.swift
Last active May 4, 2024 11:22
NaturalLanguage Framework - NLTagger Language Support Matrix
import NaturalLanguage
let languages: [NLLanguage] = [
.amharic, .arabic, .armenian, .bengali, .bulgarian,
.burmese, .catalan, .cherokee, .croatian, .czech,
.danish, .dutch, .english, .finnish, .french,
.georgian, .german, .greek, .gujarati, .hebrew,
.hindi, .hungarian, .icelandic, .indonesian, .italian,
.japanese, .kannada, .khmer, .korean, .lao,
.malay, .malayalam, .marathi, .mongolian, .norwegian,