Skip to content

Instantly share code, notes, and snippets.

View rjchatfield's full-sized avatar

Smiley Rob rjchatfield

View GitHub Profile
@nicklockwood
nicklockwood / Shape.swift
Created December 31, 2022 18:56
PolymorphicCoding.swift
import Foundation
// Here's a pretty typical scenario where you want to encode a polymorphic type -
// in this case a Shape type that can be either a Square or Circle. Swift provides
// a nice pattern for doing this in a type-safe way using enums:
struct Circle: Codable {
var radius: Int
}
@swiftui-lab
swiftui-lab / showSizes.swift
Last active April 2, 2024 22:37
A debugging modifier for SwiftUI views (showSizes)
// Author: SwiftUI-Lab (swiftui-lab.com)
// Description: Implementation of the showSizes() debugging modifier
// blog article: https://swiftui-lab.com/layout-protocol-part-2
import SwiftUI
struct MeasureExample: View {
var body: some View {
VStack {
@chriseidhof
chriseidhof / script.swift
Last active February 21, 2023 05:12
SwiftUI
import SwiftSyntax
import SwiftSemantics
import Foundation
let source = try! String(contentsOf: URL(fileURLWithPath: "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64e.swiftinterface"))
var collector = DeclarationCollector()
let tree = try SyntaxParser.parse(source: source)
tree.walk(&collector)
@Cosmo
Cosmo / SwiftUI-SymbolTable.swift
Created November 7, 2019 06:50
Name List / Symbol Table of SwiftUI
(extension in :Animatable< where A.AnimatableData == EmptyAnimatableData>.animatableData.getter : EmptyAnimatableData
(extension in :Animatable< where A.AnimatableData == EmptyAnimatableData>.animatableData.modify : EmptyAnimatableData
(extension in :Animatable< where A.AnimatableData == EmptyAnimatableData>.animatableData.setter : EmptyAnimatableData
(extension in :Animatable< where A: VectorArithmetic>.animatableData.getter : A
(extension in :Animatable< where A: VectorArithmetic>.animatableData.modify : A
(extension in :Animatable< where A: VectorArithmetic>.animatableData.setter : A
(extension in :Button< where A == PrimitiveButtonStyleConfiguration.Label>.init(PrimitiveButtonStyleConfiguration) -> Button<PrimitiveButtonStyleConfiguration.Label>
(extension in :Button< where A == Text>.init(_: LocalizedStringKey, action: () -> ()) -> Button<Text>
(extension in :Button< where A == Text>.init<A where A1: StringProtocol>(_: A1, action: () -> ()) -> Button<Text>
(extension in :CoreGraphics.CGFloat.magnitudeSqu
@mattt
mattt / UIViewControllerPreview.swift
Last active January 8, 2024 23:09
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
@Ashton-W
Ashton-W / Breakpoints_v2.xcbkptlist
Last active January 25, 2023 09:28
My User Breakpoints_v2.xcbkptlist
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "2"
version = "2.0">
<Breakpoints>
<!-- All Exceptions -->
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
@myusuf3
myusuf3 / delete_git_submodule.md
Created November 3, 2014 17:36
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@atcruice
atcruice / gist:8a3b0ab197bd5931a48c
Created May 10, 2014 12:08
C++ stream redirection for testing
// save current buffer
streambuf* coutBak = cout.rdbuf();
// setup temp stream
stringstream coutBuf;
// redirect to temp
cout.rdbuf(coutBuf.rdbuf());
// test against contents of coutBuf.str()
@atcruice
atcruice / gtestXcode5Guide.md
Created March 26, 2014 12:24
A guide for using the Google Testing Framework with Xcode 5 on Mac OS X

XcodeGuide (updated)

A guide for using the Google Testing Framework with Xcode 5 on Mac OS X

Assumed knowledge

  • basic command line chops
  • elementary Xcode 5 skills: project creation, target creation, scheme management/editing and building

Quick start

  1. Download the source from the website using this command:
@ijy
ijy / sublime-text-3-setup.md
Last active January 15, 2024 14:21
My Sublime Text 3 setup.

Sublime Text 3 Setup

Install Package Control

Install Package Control for easy package management.

  1. Open the console with Ctrl+`
  2. Paste in the following: