Skip to content

Instantly share code, notes, and snippets.

View perlguy99's full-sized avatar

Brent Michalski perlguy99

View GitHub Profile
@perlguy99
perlguy99 / SwiftUI_Extensions.md
Last active March 4, 2020 17:09
SwiftUI_Extensions

SwiftUI Extensions

Using ForEach with raw values

(So we don't have to use id: .self)

Reference

extension ForEach where Data.Element: Hashable, ID == Data.Element, Content: View {
    init(values: Data, content: @escaping (Data.Element) -> Content) {
@perlguy99
perlguy99 / SwiftUI_Buttons.md
Last active February 26, 2020 20:03
SwiftUI Buttons & TextFields
@perlguy99
perlguy99 / FavoriteSwiftTips.md
Last active March 5, 2020 17:51
My Favorite Swift Tips & Tricks & Articles

My Favorite Swift Tips & Tricks & Articles

iOS Dev Directory

iOS Dev Directory

Static factory methods in Swift

  • Great info on crating test stubs, extensions, etc.
  • Shows how to clearly separate setup code from actual logic.
  • Shows great alternatives to subclassing
@perlguy99
perlguy99 / KeyboardAwareModifier.swift
Last active October 23, 2020 04:22
SwiftUI Keyboard Aware Modifier
//
// KeyboardAwareModifier.swift
// KeyboardTest
//
import SwiftUI
import Combine
struct KeyboardAwareModifier: ViewModifier {
@State private var keyboardHeight: CGFloat = 0
@perlguy99
perlguy99 / Semantic_Versioning.md
Last active December 13, 2019 15:28
Semantic Versioning

Semantic versioning (SemVer)

Example

If you look at a version like 1.5.3, then the 1 is considered the major number, the 5 is considered the minor number, and the 3 is considered the patch number.

If developers follow SemVer correctly, then they should:

  • Change the patch number when fixing a bug as long as it doesn’t break any APIs or adds features.
  • Change the minor number when they added features that don’t break any APIs.
  • Change the major number when they do break APIs.
@perlguy99
perlguy99 / SwiftResult.md
Created December 12, 2019 14:57
Swift Result Type

Swift Result

Thanks to Paul Hudson, Hacking with Swift

//
//  ContentView.swift
//  ResultTypeTest
//
//  Created by Michalski (US), James B on 12/12/19.
//  Copyright © 2019 Perlguy, Inc. All rights reserved.
@perlguy99
perlguy99 / SwiftSaveImageToFile.md
Last active December 11, 2019 20:53
Swift Save Image to a file

How To Save a UIImage to a file

Thanks to Paul Hudson Hacking with Swift

func getDocumentsDirectory() -> URL {
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    return paths[0]
}
@perlguy99
perlguy99 / getDocumentsDirectory.md
Last active December 11, 2019 20:47
Get Documents Directory

Swift Get Documents Directory

func getDocumentsDirectory() -> URL {
    // find all possible documents directories for this user
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)

    // just send back the first one, which ought to be the only one
    return paths[0]
}
@perlguy99
perlguy99 / MoreSwiftUI.md
Last active December 11, 2019 17:58
More swiftUI
@perlguy99
perlguy99 / CustomBindings.md
Created December 9, 2019 16:37
Custom Bindings (for property wrappers)

Custom Bindings

Thanks to Paul Hudson

This won't work because the @State property wrapper doesn't actually modify the value directly...

    @State private var blurAmount: CGFloat = 0 {
        didSet {
 print("New value is \(blurAmount)")