Skip to content

Instantly share code, notes, and snippets.

View ra9r's full-sized avatar

RA9R ra9r

View GitHub Profile
@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 {
@ra9r
ra9r / AuthModel.swift
Last active September 28, 2022 09:56
Example of how to authenticate with Biometrics
func signInWithBiometrics() {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "Please authenticate yourself to unlock your places."
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authenticationError in
if success {
Task { @MainActor in
@ra9r
ra9r / KeychainStorage.swift
Created September 28, 2022 08:06
A property wrapper for Keychain storage
import SwiftUI
import KeychainAccess
@propertyWrapper
struct KeychainStorage<T: Codable>: DynamicProperty {
typealias Value = T
let key: String
@State private var value: Value?
init(wrappedValue: Value? = nil, _ key: String) {
@ra9r
ra9r / FirebaseAuthRule.md
Created September 27, 2022 09:56
This is an example of how to restrict read, edit, update to content owner only.
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents/weight {
    match /{document=**} {
        allow write: if true;
      allow read, write, delete: if
          request.auth != null && request.auth.uid == d;
    }
 }
@ra9r
ra9r / CloudKitExample.swift
Created September 26, 2022 09:27
Cheatsheet for querying CloudKit
// Configuration
let identifier = "iCloud.{your-container-name}"
let token = "{your-token-generated-from-cloudkit-console}"
let container = CKWSContainer(identifier: identifier, token: token, enviornment: .development)
// Create an operation that queries all records of the "ExampleType"
let queryOperation = CKWSQueryOperation(query: CKWSQuery(recordType: "ExampleType"))
queryOperation.recordMatchedBlock = { recordID, result in
@ra9r
ra9r / CustomBGListExample.swift
Created September 26, 2022 04:07
This is how to change the background of a List. It is no longer necessary to reference UITableView.appearance().
// This is how to change the background of a List.
// It is no longer necessary to reference UITableView.appearance()
List {
// list content
}
.scrollContentBackground(.hidden) // <-------- Here is the magic
@ra9r
ra9r / Extension+UserDefaults.swift
Created September 25, 2022 11:36
Adding support for loading and saving JSON to UserDefaults
extension UserDefaults {
static func loadJSON<T>(forKey: String) -> T? {
let defaults = UserDefaults.standard
if let data = defaults.object(forKey: forKey) as? Data {
let decoder = JSONDecoder()
if let loadedData = try? decoder.decode(T.self, from: data) {
return loadedData
}
}
return nil
@ra9r
ra9r / list-example.swift
Created September 25, 2022 04:10
Styling SwiftUI List backgrounds
List {
}
.onAppear {
// If you set the underlying UITableView appearance to "clear"
// it will allow the view's background colors to show through.
UITableView.appearance().backgroundColor = UIColor.clear
UITableViewCell.appearance().backgroundColor = UIColor.clear
}
@ra9r
ra9r / proguard-rules.pro
Created July 4, 2019 20:32
Proguard Properties for Flutter and Firebase #flutter #firebase #android
## Flutter wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
# Basic ProGuard rules for Firebase Android SDK 2.0.0+
-keep class com.firebase.** { *; }
@ra9r
ra9r / install-google-services.sh
Created June 29, 2019 23:53
How to install GoogleService-Info.plist and google-services.json from env variables #codemagic #cicd
#!/usr/bin/env sh
set -e # exit on first failed commandset
echo $ANDROID_FIREBASE_SECRET | base64 --decode > $FCI_BUILD_DIR/android/app/google-services.json
echo $IOS_FIREBASE_SECRET | base64 --decode > $FCI_BUILD_DIR/ios/Runner/GoogleService-Info.plist