Skip to content

Instantly share code, notes, and snippets.

View ppeelen's full-sized avatar
🎯
Focusing, always!

Paul Peelen ppeelen

🎯
Focusing, always!
View GitHub Profile
import SwiftUI
@main
struct SettingsDemoApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
Settings {
@ppeelen
ppeelen / GeneralSettingsView.swift
Created May 4, 2024 11:06
The result of the GeneralSettingsView swift file.
import SwiftUI
struct GeneralSettingsView: View {
@State private var settingOneValue = false
@State private var settingTwoValue = false
@State private var settingThreeValue = false
var body: some View {
Form {
@ppeelen
ppeelen / String+Sanitiser.swift
Last active December 11, 2023 07:43
A simple sanitiser for Swift strings. Removed certain sensitive information; great for using in logs.
extension String {
/**
Sanitizes the string by obscuring sensitive information.
- Returns: A sanitized version of the string where sensitive information is replaced with `*******`.
This method searches for specific keys (namely `access_token`, `refresh_token`, and `id_token`) in various formats including JSON-like strings, query strings, HTTP headers, plain text, and also searches for email addresses. It replaces their associated values or the email addresses with a placeholder string to obscure sensitive information.
## Examples:
@ppeelen
ppeelen / SwiftCharts-MultiDataType-Complete.swift
Created February 13, 2023 22:13
The end result of the tutorial for multi data type in Swift Chart
import SwiftUI
import PlaygroundSupport
import Charts
// MARK: Chart implementation
struct ChartView: View {
@Binding var consumption: [Consumption]
var body: some View {
@ppeelen
ppeelen / SwiftCharts-MultiDataType-Start.swift
Last active February 13, 2023 18:30
The start of the tutorial for multi data type in Swift Chart
import SwiftUI
import PlaygroundSupport
import Charts
// MARK: Chart implementation
struct ChartView: View {
@Binding var consumption: [Consumption]
var body: some View {
@ppeelen
ppeelen / codecov.sh
Last active May 31, 2022 12:13
Generating CodeCov JSON report from CLI
# Run tests with enableCodeCov YES, e.g. fastlane scan with code_coverage: true
# In your derived_data folder, run the following:
xcrun xcresulttool merge Logs/Test/*.xcresult --output-path bundle.xcresult # Combines all the XCResult files
xcrun xccov view --report --json bundle.xcresult > CodeCov-report.json # Generates the report into a JSON file
@ppeelen
ppeelen / DictionaryComparison.swift
Created October 12, 2021 05:59
Dictionary comparison
import Foundation
let dictOne: [String: String] = [
"key1": "value one",
"key2": "value two",
"key3": "value three",
"key4": "value four"
]
let dictTwo: [String: String] = [
@ppeelen
ppeelen / ArrayPartition.swift
Created August 19, 2021 19:52
This extension will partition an array into an array with sub items depending on the parent item. It is mean to de-flatten a flattened array.
import Foundation
// The definition of our struct
struct FooBar: Equatable{
enum ItemType {
case main, sub
}
let itemType: ItemType
let name: String
@ppeelen
ppeelen / RawRepresentableVsVar.swift
Last active June 14, 2021 10:14
An example on why not to try to reinvent the wheel, use the power of Swift.
import Foundation
enum FooBar: String, CaseIterable {
case Foo
case Bar
}
enum BarFoo: CaseIterable {
case Bar
case Foo
@ppeelen
ppeelen / LazyFilter.swift
Last active June 9, 2021 14:35
Swift: Lazy filter with prefix. Check if occurrence of X happens more than Y times using filter
struct FooBar {
let state: Bool
func isTrue() -> Bool { state } // Called 1000 times
func isFalse() -> Bool { !state } // Called 92 times
}
let fooList = (0..<1000).compactMap { n in FooBar(state: Bool.random()) }
let start = CFAbsoluteTimeGetCurrent()
if fooList.filter({ $0.isTrue() }).count > 1 {