Skip to content

Instantly share code, notes, and snippets.

View CTMacUser's full-sized avatar

Daryle Walker CTMacUser

View GitHub Profile
@tomduckering
tomduckering / ValueTransformer.swift
Last active October 25, 2018 23:49 — forked from gonzalezreal/ValueTransformer.swift
Type safe NSValueTransformer
import Foundation
private class BasicValueTransformer: ValueTransformer {
let transform: (AnyObject?) -> (AnyObject?)
init(transform: @escaping (AnyObject?) -> (AnyObject?)) {
self.transform = transform
}
// MARK: NSValueTransformer
@rnapier
rnapier / NSData.bytesView.swift
Last active January 30, 2019 00:40
Bytes collection for NSData
import Foundation
// Why bytesView rather than just extending NSData directly?
// Because this way we can keep our extension internal and not conflict
// with someone who imports us and has also extended NSData.
// If you're top-level code, you can just hoist everyting up to NSData directly.
internal extension NSData {
var bytesView: BytesView { return BytesView(self) }
}
@Gankra
Gankra / OwnershipTLDR.md
Last active April 3, 2019 22:44
Swift Ownership Manifesto TL;DR

Swift Ownership Manifesto TL;DR

Most of the manifesto is background and detailed definitions -- if you're confused or want details, read the manifesto!

https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170213/032155.html

Note also that manifestos aren't complete proposals -- syntax and details may change!

One piece of background: inout is kinda complicated because it can be used on computed properties -- foo(&val.x) might be sugar for

import UIKit
import XCPlayground
class ViewController: UIViewController {
func action() { print("Bing!") }
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .whiteColor()
@IanKeen
IanKeen / Example.swift
Last active July 10, 2019 22:02
Small utility methods to simplify dealing with Reusable items i.e. table/collection view cells
//`UITableViewCell` and `UICollectionViewCell` are `Reusable` by defaut
//Use the extension method to dequeue an instance of the appropriate `Reusable`
class MyVC: UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
tableView
.registerReusable(FooCell.self)
.registerReusable(BarCell.self)
}
// @discardableResult to be added
// @noescape needs to move to type annotation
// needs to add _ for item
public func with<T>(item: T, @noescape update: (inout T) throws -> Void) rethrows -> T {
var this = item; try update(&this); return this
}
@pyrtsa
pyrtsa / gist:2275320
Created April 1, 2012 13:27
C++11 metaprogramming
// Here are a few tricks I've used with the trunk versions of clang and libc++
// with C++11 compilation turned on. Some might be obvious, some not, but at
// least they are some kind of improvement over their C++03 counterparts.
//
// Public domain.
// =============================================================================
// 1) Using variadic class templates recursively, like in the definitions for
// "add<T...>" here:
@rxwei
rxwei / upstreaming-swift-autodiff.md
Last active January 28, 2020 11:06
Upstreaming Swift AutoDiff

Upstreaming Swift AutoDiff

Author: Richard Wei (rxwei@google.com) on behalf of the Swift for TensorFlow team

Last updated: October 2, 2019

Overview

The differentiable programming feature (AutoDiff) has been incubated in the 'tensorflow' branch of apple/swift since December 2017 and released as part of the Swift for TensorFlow toolchains. The Differentiable Programming Mega-Proposal, which serves as a manifesto, received general positive feedback from the community, but there is a long way between receiving conceptual approval and obtaining Swift Evolution approval of such a large feature. We would like to merge the pieces into the 'master' branch under a gate to further development and bake the feature on master, just like Apple develops its major features

@d-ronnqvist
d-ronnqvist / Thoughts on removedOnCompletion in SparkRecordingCircle.md
Last active May 16, 2020 02:51
What I think is wrong with the Spark Recording Circle code and why

There was [a tweet][tweetSoto] a couple of days ago that resulted in a discussion/question about what it wrong with the usage of removedOnCompletion = NO in the [SparkRecordingCircle code][code] for that [Subjective-C post][post].

We all kept saying that the explanation doesn't fit in a tweet, so here is my rough explanation about the issues.

But, let me first say that I think that the Subjective-C articles are reallt cool and useful to learn from. This is trying to reason about the general usage of removedOnCompletion = NO, using that code as an example, since that was what was discussed on twitter.


The root problem, as [Nacho Soto pointed out][rootProblem], is that removedOnCompletion = NO in combination with fillMode = kCAFillModeForwards is almost always used when you are not updating the model layer. This means that after the animation has finished, what you see on screen is not reflected in the property of the layer. The biggest issue that this can cause is that all the

@jjrscott
jjrscott / BidirectionalCollection+RegularExpressions.swift
Created July 15, 2020 21:01
Reimplementation of Brian Kernighan's Regular Expression Matcher on BidirectionalCollection
//
// RegularExpression.swift
// RegularExpressions
//
// Created by John Scott on 15/07/2020.
//
// Original matching implementation Brian Kernighan : https://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html
// Swift port Ben Cohen : https://github.com/apple/swift/blob/a9eee38e109e3d99f103a9bee71bed4422fbb6fd/benchmark/single-source/StringMatch.swift
import Foundation