Skip to content

Instantly share code, notes, and snippets.

View hartbit's full-sized avatar
👨‍💻
Swifting, one commit at a time

David Hart hartbit

👨‍💻
Swifting, one commit at a time
  • Atipik Sàrl & Witty Wings SA
  • Geneva, Switzerland
View GitHub Profile
tmp=`mktemp -d -t swiftpm`
git clone --quiet https://github.com/apple/swift-package-manager $tmp > /dev/null
swift package --package-path $tmp resolve > /dev/null
time swift test --package-path $tmp --parallel
system_profiler SPHardwareDataType
swift --version
@hartbit
hartbit / crash.swift
Created July 23, 2019 15:50
SwiftUI Crash
// To reproduce crash:
// 1. Navigate to second tab
// 2. Toggle the switch
// 3. Navigate to first tab
// Note: removing the NavigationView in the second tab avoids the crash
final class ViewModel: BindableObject {
var tab: Int = 0 { willSet { willChange.send(()) } }
var isOn: Bool = false { willSet { willChange.send(()) } }
let willChange = PassthroughSubject<Void, Never>()
import RxSwift
import RxCocoa
final class Value<T>: ObservableType {
private let subject: BehaviorSubject<T>
var value: T {
get {
return try! subject.value()
}

I started with this:

extension Book {
    static func all(byAuthorWithId authorId: Int64) -> QueryInterfaceRequest<Book> {
        return Book.filter(Book.authorId == authorId && Book.isPublished)
    }
}

Given a protocol that refines CodingKey:

protocol DocumentedCodingKey: CodingKey {
    var documentation: String { get }
}

I'd like to be able to conform the automatically generated CodingKeys to it:

@hartbit
hartbit / AutoRowConvertible.generated.stencil
Last active February 10, 2018 16:43
GRDB Sourcery Templates
// Generated using Sourcery 0.10.0 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
import GRDBCipher
extension BookViewModel: RowConvertible {
init(row: Row) {
title = row["title"]
genre = row["genre"]
authorName = row["authorName"]
@hartbit
hartbit / proposal.md
Last active November 11, 2017 22:43
Improving capturing semantics of local functions

Improving capturing semantics of local functions

Introduction

This proposal improves local functions by giving them the same memory safety and expressive power as closures in regards to capturing semantics.

Hi Rick,

Thanks for taking the time to reply. I discussed the same argument with Ankit Aggarwal, and here are my counter-arguments:

  • It seems to me like the survey should take into account the developer population using each tool. If we are doing such a survey to see what tool a programmer coming to Swift is coming from, there is much less chance he has previous knowledge of rebar3 than of npm. The majority of the ones which are widely used seem to use install: I’ve updated the survey bellow by ordering them by stars on GitHub. It’s a crude approximation of developer population, but I think it’s good enough for us.
  • If we do end up implementing install to mean install to the system, how would we update the system packages?
    • Solution 1 would be to add a —system/—global flag on update. In that case, that would bring inconsistency by using two different commands to “install/resolve” and one command but different flags for updating.
  • Solution 2 would be to introduce a different comma
@hartbit
hartbit / Package.swift
Created February 27, 2017 21:09
Swift Package Manager SystemPackageProvider Syntax
let package = Package(
name: "Copenssl",
pkgConfig: "openssl",
providers: [
.brew("openssl"),
.apt("openssl", "libssl-dev")
]
)
@hartbit
hartbit / Naming-improvements.md
Last active June 16, 2016 23:06
Proposed naming changes to Framework APIs to conform to Swift Design Guidelines

CoreMotion

CMMotionActivityManager

Two modifications here:

  • Remove the starting suffix as it only really pertains to the first argument.
  • Rename the queue label to on to reduce the ambiguity from using two label with the same name (to).
- public func queryActivityStarting(from start: Date, to end: Date, to queue: OperationQueue, withHandler handler: CoreMotion.CMMotionActivityQueryHandler)