Skip to content

Instantly share code, notes, and snippets.

View mortenbekditlevsen's full-sized avatar

Morten Bek Ditlevsen mortenbekditlevsen

View GitHub Profile

The Swift Evolution forums are full of exciting pitches and proposals for new functionality in Swift and it’s ecosystem.

After the sunsetting of the Swift Weekly Brief I’ve been missing a digest of news from SE.

I will be no means try to replace the Swift Weekly Brief - since I don’t have the bandwidth for such an undertaking - but I’ll try to present a few of the pitches and proposals that I find interesting.

SE-0380, if and switch expressions

swift-evolution/0380-if-switch-expressions.md at main · apple/swift-evolution · GitHub

import Foundation
struct Wrapper: Codable, Hashable, RawRepresentable, ExpressibleByStringLiteral, CodingKeyRepresentable {
typealias StringLiteralType = String
var rawValue: String
init(rawValue: String) {
self.rawValue = rawValue
}
import Foundation
enum DecodeError: Error {
case err
}
struct Foo: Codable {
var a: String
}
enum QueryPredicate {
case isEqualTo(_ field: String, _ value: Any)
case isNotEqualTo(_ field: String, _ value: Any)
case isIn(_ field: String, _ values: [Any])
case isNotIn(_ field: String, _ values: [Any])
case arrayContains(_ field: String, _ value: Any)
case arrayContainsAny(_ field: String, _ values: [Any])
@mortenbekditlevsen
mortenbekditlevsen / Observable.swift
Created January 26, 2020 10:13
Swift 5.2 only - this will not work in Swift 5.1
import Combine
import SwiftUI
@propertyWrapper
class Observable<T>: ObservableObject {
@Published var wrappedValue: T
init(wrappedValue: T) {
self.wrappedValue = wrappedValue
}
}
@mortenbekditlevsen
mortenbekditlevsen / LetItSnow.swift
Created December 18, 2019 12:58
Half failed attempt at a koch snowflake. Looks pretty tho'! ;-)
import SwiftUI
struct Triflake: View {
let angle: Angle
let level: Int
init(angle: Angle, level: Int) {
self.angle = angle
self.level = level
}
class TestResolver {
var identifier: String
@ResolveKeypathLazily(keyPath: \TestResolver.identifier)
var hamster: Int = 1
init(identifier: String) {
self.identifier = identifier
}
}
@mortenbekditlevsen
mortenbekditlevsen / Nesting.swift
Created July 21, 2019 06:18
PropertyWrapper nesting
@propertyWrapper
struct A<T> {
private var _storage: T
var wrappedValue: T {
get { _storage }
mutating set { _storage = newValue }
}
}
@propertyWrapper
import SwiftUI
struct TextFormatting: ExpressibleByStringLiteral, ExpressibleByStringInterpolation {
struct StringInterpolation: StringInterpolationProtocol {
var output: Text = Text(verbatim: "")
init(literalCapacity: Int, interpolationCount: Int) {
// TODO
}
@mortenbekditlevsen
mortenbekditlevsen / PixelBasedLayoutConstraint.swift
Created April 6, 2019 12:03
Any constants in the constraint will be interpreted as pixels instead of points
public class PixelBasedLayoutConstraint: NSLayoutConstraint {
override public func awakeFromNib() {
super.awakeFromNib()
constant /= UIScreen.main.scale
}
}