Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Grebenyuk kean

View GitHub Profile
View navigation-view.swift
struct ContentView: View {
@State private var isShowingDetailView = false
var body: some View {
NavigationView {
NavigationLink(destination: Text("Second View"), isActive: $isShowingDetailView) {
Text("Show Detail")
}
.navigationBarTitle("Navigation")
}
View Notes.md

With @inlinable, Swift compiler is able to optimize the entire for in loop away, which is not possible without it.

@kean
kean / Example.swift
Last active Mar 19, 2020
FetchedImage
View Example.swift
public struct ImageView: View {
@ObservedObject var image: FetchImage
public var body: some View {
ZStack {
Rectangle().fill(Color.gray)
image.view?
.resizable()
.aspectRatio(contentMode: .fill)
}
View Future+Combine.swift
import Future
import Combine
public extension Future {
var publisher: Combine.Future<Value, Error> {
Combine.Future { fulfill in
self.on(success: {
fulfill(.success($0))
}, failure: {
fulfill(.failure($0))
View SearchView.swift
struct SearchView: View {
@ObservedObject var viewModel: SearchViewModel
var body: some View {
VStack {
TextField("Search", text: $viewModel.query)
List(viewModel.songs) {
Text($0.name)
}
}
@kean
kean / _DynamicProperty.swift
Last active Feb 23, 2020
_DynamicProperty
View _DynamicProperty.swift
// A speculative _ViewRendererHost implementation which uses Mirror (Swift reflection) to find all
// of the dynamic properties (`DynamicProperty`) associated with a given view (`View`), observe
// the changes to these properties and automatically refresh the view whenever any of these property change.
protocol _DynamicProperty {
var objectWillChange: AnyPublisher<Void, Never> { get }
}
extension ObservedObject: _DynamicProperty {
var objectWillChange: AnyPublisher<Void, Never> {
View FetchedEntities.swift
// The MIT License (MIT)
//
// Copyright (c) 2020 Alexander Grebenyuk (github.com/kean).
import CoreData
final class FetchedEntities<Element: NSManagedObject>: NSObject, NSFetchedResultsControllerDelegate, RandomAccessCollection, ObservableObject {
private let controller: NSFetchedResultsController<Element>
init(context: NSManagedObjectContext, request: NSFetchRequest<Element>) {
@kean
kean / FutureCompatible.swift
Created Nov 20, 2019
FutureCompatible.swift
View FutureCompatible.swift
// The MIT License (MIT)
//
// Copyright (c) 2016-2019 Alexander Grebenyuk (github.com/kean).
import Foundation
/// Future extenions.
public struct FutureExtension<Base> {
/// Base object to extend.
public let base: Base
View multi-platform-framework.xcconfig
// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974
SUPPORTED_PLATFORMS = iphoneos macosx appletvos watchos iphonesimulator appletvsimulator watchsimulator
SWIFT_VERSION = 4.2
IPHONEOS_DEPLOYMENT_TARGET = 9.0
MACOSX_DEPLOYMENT_TARGET = 10.11
You can’t perform that action at this time.