Skip to content

Instantly share code, notes, and snippets.

View gdavis's full-sized avatar

Grant Davis gdavis

View GitHub Profile
@gdavis
gdavis / swiftui-state.markdown
Last active December 14, 2023 03:07
Swift UI State Management

Swift UI State Management

Storing state for Child View Models

SwiftUI is all about state, and maintaining that state can be rather difficult when you have more than a few properties stored as @State for your view. It is common practice to use a view model to store the state outside of the view, since our views are constantly recreated as our state changes. Keeping what state you want in memory can provide a challenge, much more so than it may seem at first glance.

With SwiftUI 2, using @StateObject will keep a view model from being recreated with each rendering of a view's body. If the parent view is creating the view model, and then passing that down to the child view, that view model will also be recreated with each rendering of that parent view body.

struct ParentView: View {
  var body: some View {
@gdavis
gdavis / assignNoRetain.swift
Created February 10, 2021 18:03
Combine assign method without the memory leak
extension Publisher where Self.Failure == Never {
public func assignNoRetain<Root>(to keyPath: ReferenceWritableKeyPath<Root, Self.Output>, on object: Root) -> AnyCancellable where Root: AnyObject {
sink { [weak object] (value) in
object?[keyPath: keyPath] = value
}
}
}
@gdavis
gdavis / desymbolication-terminal.markdown
Last active August 26, 2021 13:39
De-symbolicating crash reports via Terminal
  1. download the crash log, dSYM, and place in the same directory

  2. copy the symbolicatecrash executable from Xcode tools and place in the directory in step 1 (or create an alias pointing to it)

  3. set the environment variable for the developer directory

export DEVELOPER_DIR=$(xcode-select --print-path)

  1. run the symbolicatecrash with arguments to the crash log and dSYM > ./symbolicatecrash -v [crashfilename].crash [appname].app.dSYM
Hello, I'm contacting you today in response to the FCC's vote today to repeal Net Neutrality.
I want to urgently request that Colorado join New York state in suing the FCC over this action. By repealing the protections put in place in 2015, large corporations that own both news outlets and act as internet service providers, can now freely choose what news, and therefore access to information, their users have access to.
By controlling this access to information, these corporations can dictate what you learn about political candidates, controversial issues, and anything other than what the ISPs deem they want you to know. This undermines the foundations of democracy which depends on an having a public that is informed and unbiased.
While I would personally say we have not had a true democracy in decades, this further establishes the power that corporations wield and further entrenches us into a corporatocracy. For example, Comcast already maintains a virtual monopoly for access to high-speed broadband in
@gdavis
gdavis / gist:70f6dae2f3a9d9e9351c5f3e84f23e5e
Created September 18, 2017 17:37
Remove unwanted Xcode Console Messages

Add this to the current scheme's environment variables:

OS_ACTIVITY_DT_MODE: NO

@gdavis
gdavis / gist:23cbc7b49aa37ba3ef5f001c7779a6f3
Last active July 14, 2017 15:31
Xcode 9 – Enable Simulator to work in fullscreen mode

defaults write http://com.apple .dt.Xcode ShowDVTDebugMenu YES

Source

@gdavis
gdavis / XcodeWarnings.sh
Created March 9, 2016 01:43
Xcode Run Script that highlights TODO, FIXME and more as warnings.
KEYWORDS="TODO|FIXME|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | \
xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | \
perl -p -e "s/($KEYWORDS)/ warning: \$1/"
@gdavis
gdavis / GDILog.h
Last active August 29, 2015 14:05
GDILog - Replacement for NSLog
//
// GDILog.h
// GDILog
//
// Created by Grant Davis on 8/18/14.
// Copyright (c) 2014 Grant Davis Interactive, LLC. All rights reserved.
//
#ifdef DEBUG
#include <string.h>
@gdavis
gdavis / .gitignore
Last active August 29, 2015 14:02 — forked from adamgit/.gitignore
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,
@gdavis
gdavis / .gitignore
Created February 24, 2014 16:23 — forked from adamgit/.gitignore
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,