Skip to content

Instantly share code, notes, and snippets.

@johndelong
johndelong / SwiftUI.md
Last active November 16, 2021 21:58
General notes on the core components of SwiftUI

@ObservedObject / @Published

The ObservableObject conformance allows instances of a class to be used inside views, so that when important changes happen the View will reload.

The @Published property wrapper tells SwiftUI that changes to a property should trigger View reloads.

class Contact: ObservableObject {
    @Published var name: String
 @Published var age: Int
@johndelong
johndelong / ViewController.swift
Last active March 28, 2021 00:26
Infinite Scrolling Final
//
// ViewController.swift
// Example
//
// Created by John DeLong on 5/11/16.
// Copyright © 2016 delong. All rights reserved.
//
import UIKit
@johndelong
johndelong / snippets.swift
Created April 5, 2017 18:33
Fitting Views to Their Content (edges cases)
/**
Calculates and adjusts the frame of a web view to fit its content
http://stackoverflow.com/a/3937599/7066201
*/
func calculateWebViewSize() {
self.view.layoutIfNeeded()
var frame = self.webview.frame
frame.size.height = 1
self.webview.frame = frame
@johndelong
johndelong / ViewController.swift
Last active October 19, 2016 17:35
Infinite Scrolling Setup
//
// ViewController.swift
// Example
//
// Created by John DeLong on 5/11/16.
// Copyright © 2016 delong. All rights reserved.
//
import UIKit