Skip to content

Instantly share code, notes, and snippets.

View ricardopereira's full-sized avatar
🏠
Working from home

Ricardo Pereira ricardopereira

🏠
Working from home
View GitHub Profile
@insidegui
insidegui / devicectl.sh
Created October 19, 2023 21:58
Helper functions for using devicectl to kill processes on connected iOS devices
# Add to your zsh profile
function devicepid() {
if [ -z "$1" ]; then
echo "Usage: devicepid <device-name> <search>"
echo "Example: devicepid 'iPhone 15 Pro Max' SpringBoard"
return 1
fi
if [ -z "$2" ]; then
@swiftui-lab
swiftui-lab / grid-trainer.swift
Last active March 29, 2024 01:46
A grid trainer for Grid views
// Author: SwiftUI-Lab (swiftui-lab.com)
// Description: this learning tool is designed to showcase the different
// Grid and GridRow view options, added in SwiftUI 2022. It is part of the
// blog article: https://swiftui-lab.com/eager-grids
//
import SwiftUI
import UniformTypeIdentifiers
// The root view of the application
struct ContentView: View {
@mluisbrown
mluisbrown / xstrings.swift
Last active June 29, 2022 15:09
Swift script to extract all string literals from a Swift source file in the format of a Localizable.strings file
#!/usr/bin/swift
import Foundation
func processFile(_ path: String, keyPrefix: String?) {
guard let file = freopen(path, "r", stdin) else {
fputs("Failed to open file.\n", stderr)
return
}
defer {
fclose(file)
@dive
dive / fix_ios_15_simulator_spotlight_cpu.sh
Created December 16, 2021 10:35
Fix the iOS 15 Simulator high CPU usage due to the Spotlight/Suggestions Engine
#!/bin/env sh
disable_suggestions() {
if [ -d "$1" ]; then
pushd "$1" || return
find . -name com.apple.suggestions.plist \
-exec echo {} \; \
-exec plutil -replace SuggestionsAppLibraryEnabled -bool NO {} \;
popd || return
fi
@aclima93
aclima93 / LeakCheckTestCase.swift
Last active August 10, 2021 08:28
Automated detection of memory leaks in Unit Tests
class LeakCheckTestCase: XCTestCase {
private var excludedProperties = [String: Any]()
private var weakReferences = NSMapTable<NSString, AnyObject>.weakToWeakObjects()
// MARK: - SetUp
override func setUpWithError() throws {
try super.setUpWithError()
@krzysztofzablocki
krzysztofzablocki / NetworkResponseConvertible.swift
Last active August 22, 2021 12:09
A good way to deal with mapping network data to your local models in a consistent way, This is how @noremac standardised it in Times codebase
import Combine
import Foundation
/// This protocols allows you to declare your type as having a distinct network
/// representation.
///
/// Rather than writing and maintaining a custom `Decodable` implementation for
/// your type, declare a brand new struct that exactly matches the expected
/// network response, and then write an initializer for your actual type that
/// accepts a `NetworkResponse`.
extension UIHostingController {
convenience public init(rootView: Content, ignoreSafeArea: Bool) {
self.init(rootView: rootView)
if ignoreSafeArea {
disableSafeArea()
}
}
func disableSafeArea() {
@amelnychuck
amelnychuck / FakeSettingsView.swift
Last active August 5, 2021 11:06
The goal of this 15min project is to showcase just how easy it is to fake an iOS settings screen. No photoshop text errors, no inconsistencies to reconcile–just a really convincing fake settings screen : )
//
// FakeSettingsView.swift
// FakeSettings
//
// Created by Alex Melnychuck on 8/26/20.
//
// The goal of this 15min project is to showcase just how easy it is to
// fake an iOS settings screen. No photoshop text errors, no
// inconsistencies to reconcile–just a really convincing fake
@steipete
steipete / OSLogStream.swift
Last active November 7, 2023 22:25
Access streaming OSLogStore at runtime with SPI. (FB8519418) https://steipete.com/posts/logging-in-swift/
//
// OSLogStream.swift
// LoggingTest
//
// Created by Peter Steinberger on 24.08.20.
//
// Requires importing https://github.com/apple/llvm-project/blob/apple/master/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h via bridging header
import Foundation
@IanKeen
IanKeen / Example_Complex.swift
Last active January 23, 2024 07:53
PropertyWrapper: @transaction binding for SwiftUI to make changes to data supporting commit/rollback
struct User: Equatable {
var firstName: String
var lastName: String
}
@main
struct MyApp: App {
@State var value = User(firstName: "", lastName: "")
@State var showEdit = false