Skip to content

Instantly share code, notes, and snippets.

@moyerr
moyerr / SwiftUINavigation.swift
Created July 7, 2023 17:17
A demonstration of navigation in SwiftUI using NavigationStack and Environment actions
import SwiftUI
// MARK: Navigation
enum Screen: String, Hashable, CaseIterable, CustomStringConvertible {
case first, second, third
var description: String {
rawValue.capitalized
}
@mbrandonw
mbrandonw / FB10144005.md
Last active March 22, 2024 17:05
iOS 16 Navigation API feedbacks

How to execute logic when NavigationLink is tapped?

FB10144005

Currently it doesn't seem possible to execute additional logic when a navigation link is tapped with the new NavigationLink(value:) initializer. When the link is tapped it updates path state all the way back at the root NavigationStack to drive navigation, but there are many times where we need to perform logic after the tap and before the drill down.

For example, after tapping a link we may want to pre-emptively load some data to show on the drill down screen. Or we may want to perform some form validation. Or we may want to track some analytics. This does not seem possible with the current link API.

A workaround is to use Buttons instead of NavigationLinks, but then you lose all of the styling and affordances given to links, such as chevrons when used in List.

If the API for NavigationLink cannot be changed to accomodate for this, perhaps a new ButtonStyle could be introduced that allows regular buttons to take on the sty

@levibostian
levibostian / AppCoreDataManager.swift
Last active October 6, 2023 18:02
iOS CoreData ultimate document. Stack, tutorial, errors could encounter. All my CoreData experience for what works in 1 document.
import CoreData
import Foundation
protocol CoreDataManager {
var uiContext: NSManagedObjectContext { get }
func newBackgroundContext() -> NSManagedObjectContext
func performBackgroundTaskOnUI(_ block: @escaping (NSManagedObjectContext) -> Void)
func performBackgroundTask(_ block: @escaping (NSManagedObjectContext) -> Void)
func loadStore(completionHandler: ((Error?) -> Void)?)
}
@jubinjacob19
jubinjacob19 / ui_test_sharder.py
Created July 3, 2020 05:56
Python Script to shard UITests in Xcode project
import os
import errno
import sys
shard_index = sys.argv[1]
PATH = os.path.dirname(os.getcwd())
TESTSPATH = os.path.join(PATH,"Example/UITests/")
tests = []
shard_tests = ""
@skl
skl / PopSheet.swift
Created June 19, 2020 01:08
This is a workaround for iPad ActionSheets disappearing off the screen.
//
// PopSheet.swift
//
// Adapted from:
// https://stackoverflow.com/questions/56910941/present-actionsheet-in-swiftui-on-ipad
//
import SwiftUI
extension View {
@ethanhuang13
ethanhuang13 / FacebookAuth.swift
Last active March 28, 2024 08:24
FacebookAuth is for iOS app developers who need to support Facebook login but don't want to use the official SDK
//
// FacebookAuth.swift
// GitHub: ethanhuang13
// Twitter: @ethanhuang13
import AuthenticationServices
import SafariServices
/*
Updated:
@twaddington
twaddington / charles-proxy-android.md
Last active April 20, 2024 17:26
How to set up Charles Proxy for the Android Emulator.

Charles Proxy Android

Note: Consider using mitmproxy instead of Charles. There is better, more recent, documentation for using mitmproxy on Android.

Steps

1. Add the Network Security Configuration to your app

@JonnyBeeGod
JonnyBeeGod / CountdownTests.swift
Created December 25, 2019 06:41
This code allows for testing UNNotificationCenter and UNNotificationSettings
func testNotifications() {
// map all authorizationStatus with expected Result
let authorizationStatusMap: [UNAuthorizationStatus: Int] = [.authorized: 1, .denied: 0, .notDetermined: 0, .provisional: 1]
UNNotificationSettings.swizzleAuthorizationStatus()
authorizationStatusMap.forEach { (key: UNAuthorizationStatus, value: Int) in
UNNotificationSettings.fakeAuthorizationStatus = key
let mockCenter = UserNotificationCenterMock()
let mockCoder = MockNSCoder()
@kentbrew
kentbrew / finding_twitter_user_id.md
Last active March 24, 2024 16:42
Finding Twitter User IDs

Finding Twitter User IDs

User accounts on Twitter are commonly identified by screen name, which may be changed by operators when they take over an account, or have been sitting on an old account for a long time and want to transition it into malicious use.

User IDs, however, are permanent. There are several services out there that will try to find them for you but it seems like a bad idea to me, since you're alerting them to the fact that there's something interesting about this account. There's also plenty of bad advice that uses many long-since-abandoned Twitter API endpoints.

As of this writing (2018-02-18) you can view source and search for /profile_banners/, which will show something like this:

.enhanced-mini-profile .mini-profile .profile-summary {
@mbuchetics
mbuchetics / codeableEnum.swift
Created June 30, 2017 09:30 — forked from reckenrode/codeableEnum.swift
Implement Codable on an enum
struct User: Codable {
var name: String
var email: String
var id: String
var metadata: [String: MetadataType]
enum CodingKeys: String, CodingKey {
case name, email, id, metadata
}
}