Skip to content

Instantly share code, notes, and snippets.

🦅
Hacking in Swift

Adrian Z. DevAndArtist

🦅
Hacking in Swift
Block or report user

Report or block DevAndArtist

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View NavigationView_Issue.swift
import SwiftUI
struct ContentView: View {
@State var flag = true
var body: some View {
let text = "\(flag ? "HStack" : "ZStack")"
return VStack {
Text(text)
Button("change the stack") {
@DevAndArtist
DevAndArtist / fake_animation_completion.swift
Created Sep 18, 2019
SwiftUI Fake Animation completion for animations that do not overshoot the final value
View fake_animation_completion.swift
fileprivate struct _CompletionPreferenceKey: PreferenceKey {
typealias Value = CGFloat
static let defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}
@DevAndArtist
DevAndArtist / reimplemented_parts_of_swiftui.swift
Last active Jul 28, 2019
This is a custom implementation of some parts of SwiftUI which I could observe.
View reimplemented_parts_of_swiftui.swift
import CoreGraphics
final class TransactionStack {
static let shared = TransactionStack()
private var _transactions: [Transaction]
private init() {
dispatchPrecondition(condition: .onQueue(.main))
_transactions = []
@DevAndArtist
DevAndArtist / swiftui_to_uikit.swift
Last active Jul 8, 2019
Applying SwiftUI ideas to UIKit
View swiftui_to_uikit.swift
import RxSwift
import RxCocoa
import RxRelay
extension Disposable {
public func wrapIntoAnyDisposable() -> AnyDisposable {
return AnyDisposable(self)
}
}
View WWDC 2019 Labs Questions.md

WWDC 2019 Labs Questions

Size changes propagation to child view controller

In A Look Inside Presentation Controllers - WWDC 2014 session the following pattern was introduced.

  • A child view controller or a presented view controller can issue a request for size update by setting its preferredContentSize property.
  • A parent view controller or a presentation controller will receive a callback on preferredContentSizeDidChangeForChildContentContainer method.
  • At this point the receiver can decide if can allow the size request and layout the child view controller or the presented view controller.
View Property Delegates.md
View Application Development Techniques.md

Application Development Techniques

Drivable UI

@dynamicMemberLookup
struct DriverFor<Base> {
  var base: Base
View Uniquifiable.swift
public struct Unique<Key, Value>: Hashable where Key: Hashable {
public enum KeyVariant {
case key(Key)
case keyPath(KeyPath<Value, Key>)
case closure((Value) -> Key)
internal func _key(for value: Value) -> Key {
switch self {
case .key(let key):
View deinit-experiment.swift
class Ref {
weak var obj: Obj? {
didSet { print("didSet", obj as Any) }
}
}
class Obj {
weak var ref: Ref?
func unlink(from ref: Ref) {
View Cacheable.swift
protocol ValueContainer {
associatedtype Value
var value: Value { get }
init(_ value: Value)
}
extension ValueContainer where Self : Equatable, Value : Equatable {
static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.value == rhs.value
}
You can’t perform that action at this time.