Skip to content

Instantly share code, notes, and snippets.

View NeverwinterMoon's full-sized avatar
💭
Hacking at SwiftUI

Pavel Sorokin NeverwinterMoon

💭
Hacking at SwiftUI
View GitHub Profile
//
// ContentView.swift
// LikeThumbUp
//
// Created by Amos Gyamfi on 14.8.2020.
//
import SwiftUI
struct ContentView: View {
//
// ContentView.swift
// FlowLayoutST
//
// Created by Chris Eidhof on 22.08.19.
// Copyright © 2019 Chris Eidhof. All rights reserved.
//
import SwiftUI
struct FlowLayout {
@Amzd
Amzd / Binding+didSet.swift
Last active September 20, 2023 05:27
SwiftUI Binding wrappers for willSet and didSet
extension Binding {
/// Wrapper to listen to didSet of Binding
func didSet(_ didSet: @escaping ((newValue: Value, oldValue: Value)) -> Void) -> Binding<Value> {
return .init(get: { self.wrappedValue }, set: { newValue in
let oldValue = self.wrappedValue
self.wrappedValue = newValue
didSet((newValue, oldValue))
})
}
// The SwiftUI Lab
// Website: https://swiftui-lab.com
// Article: https://swiftui-lab.com/alignment-guides
import SwiftUI
struct ContentView: View {
@State var position: Int = 0
var body: some View {
@niusounds
niusounds / OrientationLiveData.kt
Created June 29, 2018 03:08
Device orientation sensor data for LiveData.
import android.arch.lifecycle.LiveData
import android.content.Context
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
data class Orientation(
val azimuth: Float,
val pitch: Float,
@y-polek
y-polek / LiveDataExt.kt
Last active November 25, 2021 01:22
'map' and 'combineLatest' transformations for LiveData
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MediatorLiveData
import android.arch.lifecycle.MutableLiveData
fun <X, Y> LiveData<X>.map(func: (X?) -> Y?): MutableLiveData<Y?> {
return MediatorLiveData<Y>().apply {
addSource(this@map) { x -> value = func(x) }
}
}
@NeverwinterMoon
NeverwinterMoon / Country.swift
Created March 27, 2018 11:38 — forked from kharrison/Country.swift
Swift Hash Functions
import Foundation
struct Country {
let name: String
let capital: String
var visited: Bool
}
extension Country: Equatable {
static func == (lhs: Country, rhs: Country) -> Bool {
@krodak
krodak / Realm+CascadeDeleting.swift
Last active April 27, 2023 19:16
Cascade deletion for RealmSwift
import RealmSwift
import Realm
protocol CascadeDeleting: class {
func delete<Entity>(_ list: List<Entity>, cascading: Bool)
func delete<Entity>(_ results: Results<Entity>, cascading: Bool)
func delete<Entity: Object>(_ entity: Entity, cascading: Bool)
}
@Herakleis
Herakleis / ViewModel+RealLifeExample.swift
Last active April 27, 2019 19:59
ViewModel+RealLifeExample
import RxSwift
import Action
enum SceneStateOutput {
case idle
case sendingNoRecipient
case sendingSomeRecipients(sendingList: [String: String])
case sending
}
@marcosgriselli
marcosgriselli / UIImage+Resize.swift
Last active February 2, 2024 07:04
UIImage Resize/Scaling
//
// UIImage+Resize.swift
//
// Created by Marcos Griselli on 6/9/17.
// Copyright © 2017 Marcos Griselli. All rights reserved.
//
import Foundation
import UIKit