Skip to content

Instantly share code, notes, and snippets.

@pakirby1
pakirby1 / BindableFetchedResultsController.swift
Last active June 28, 2021 08:45
NSFetchedResultsControllerDelegate & Combine
import Foundation
import CoreData
import Combine
import SwiftUI
class BindableFetchedResultsController<T: NSManagedObject>: NSObject, NSFetchedResultsControllerDelegate, ObservableObject {
let fetchedResultsController: NSFetchedResultsController<T>
// Publisher. clients should reference to get updates
@Published var fetchedObjects: [T]
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
import Foundation
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
@pakirby1
pakirby1 / init_storedProperties.md
Last active January 5, 2019 03:08
Various ways to initialize stored properties

The initialization process has a few constraints on what can be done within an init function.
From StackOverflow

You can't call methods on self before all non-optional instance variables are initialized. There are several ways to go around that.

  • Change properties to optionals or implicitly unwrapped optionals (not recommended)
  • Make the methods static.
  • Make the methods as a fileprivate function in the file.
  • You just have to avoid calls to self before the class is initialized.