Skip to content

Instantly share code, notes, and snippets.

View ra9r's full-sized avatar

RA9R ra9r

View GitHub Profile
@ra9r
ra9r / Configuration.swift
Last active October 15, 2023 12:16
Enum wrapper for easier info.pist access
//
// Configuration.swift
// Configurations and Flags
//
// Created by Stewart Lynch on 2021-09-27.
//
import Foundation
enum Configuration {
@ra9r
ra9r / GetInfoPlistExample.swift
Last active October 15, 2023 12:17
How to access the Info.plist values from Swift
let appBuildNumber = Bundle.main.object(forInfoDictionaryKey: "App_build_number") as? String
let appVersionNumber = Bundle.main.object(forInfoDictionaryKey: "App_version_number") as? String
@ra9r
ra9r / setup_googleservices.sh
Last active October 21, 2022 02:00
Xcode Run Script to copy GoogleService-Info.plist manually for different build configurations
# Type a script or drag a script file from your workspace to insert its path.
# Name of the resource we're selectively copying
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
# Get references to dev and prod versions of the GoogleService-Info.plist
# NOTE: These should only live on the file system and should NOT be part of the target (since we'll be adding them to the target manually)
GOOGLESERVICE_INFO_DEV=${PROJECT_DIR}/${TARGET_NAME}/GoogleService/Dev/${GOOGLESERVICE_INFO_PLIST}
GOOGLESERVICE_INFO_PROD=${PROJECT_DIR}/${TARGET_NAME}/GoogleService/Prod/${GOOGLESERVICE_INFO_PLIST}
# Make sure the dev version of GoogleService-Info.plist exists
@ra9r
ra9r / ShopContainerView.swift
Created October 18, 2022 12:19
Programmatic navigation
struct ShopContainerView: View {
@StateObject private var store = Store()
@State private var path: [Product] = []
var body: some View {
NavigationStack(path: $path) {
List(store.products) { product in
NavigationLink(product.title, value: product)
}
.task { await store.fetch() }
@ra9r
ra9r / PumpChangeCardView.swift
Created October 9, 2022 09:47
How to initialize a @StateObject inside an init()
struct PumpChangeCardView: View {
@StateObject var model: PumpChangeCardViewModel
init(_ record: PumpChangeRecord) {
self._model = StateObject(wrappedValue: PumpChangeCardViewModel(record))
}
}
@ra9r
ra9r / example.swift
Created October 9, 2022 09:46
Accessing info.plist values inside an iOS app
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String &?? "-"
@ra9r
ra9r / README.md
Created October 9, 2022 07:47
Loading different GoogleService-Info.plist for dev and prod environments

If the builds are part of a single target, the best option is to give both configuration files unique names (e.g. GoogleService-Info-Free.plist and GoogleService-Info-Paid.plist). Then choose at runtime which plist to load. This is shown in the following example:

// Load a named file.
let filePath = Bundle.main.path(forResource: "MyGoogleService", ofType: "plist")
guard let fileopts = FirebaseOptions(contentsOfFile: filePath!)
  else { assert(false, "Couldn't load config file") }
FirebaseApp.configure(options: fileopts)
@ra9r
ra9r / ContentView.swift
Created October 8, 2022 01:08
Examples of reacting to changes in TextFields
struct ContentView : View {
@State var text1 = ""
@State var text2 = ""
@StateObject var model = ViewModel()
var body: some View {
TextField("Text 1", text: $text1)
{ editing in
print("Editing?: \(editing)")
} onCommit: {
@ra9r
ra9r / sfrounded.swift
Created October 3, 2022 01:53
How to use SF Rounded Font in Swift UI
Text("Your Text").font(.system(.body, design: .rounded))
@ra9r
ra9r / MultiComponentPicker.swift
Created October 2, 2022 00:55
Fix for Multi-Component Picker on iOS 16.0
//
// MultiComponentePicker.swift
// SwiftJourney
//
// Created by Rodney Aiglstorfer on 10/2/22.
//
import SwiftUI
struct MultiComponentePicker: View {