Skip to content

Instantly share code, notes, and snippets.

View KaneCheshire's full-sized avatar

Kane Cheshire KaneCheshire

View GitHub Profile
@KaneCheshire
KaneCheshire / AnyTask.swift
Last active May 7, 2024 08:13
Type-erased Swift Task that cancels itself on deinit
/// A type-erased task that you can store in a collection
/// to allow you to cancel at a later date.
///
/// Upon deinit of the task, the task will be cancelled
/// automatically. Similar to Combine's AnyCancellable.
final class AnyTask {
/// Call this cancellation block to cancel the task manually.
let cancel: () -> Void
/// Checks whether the task is cancelled.
@KaneCheshire
KaneCheshire / Result.kt
Last active September 9, 2020 17:41
A re-implementation of Kotlin and Swift's Result type in Kotlin
sealed class Result<out S, out F: Throwable> {
data class Success<out S, out F: Throwable>(val value: S) : Result<S, F>()
data class Failure<out S, out F: Throwable>(val failure: F) : Result<S, F>()
}
@KaneCheshire
KaneCheshire / BoostedRemote.txt
Last active August 13, 2020 16:13
Boosted Board Remote Advertising Details
****************************************************************************************************************
* This document has been moved to https://github.com/KaneCheshire/remotely which has accompanying Android code *
****************************************************************************************************************
* This document is now out of date *
****************************************************************************************************************
When the remote is not in pairing mode, it advertises the following data
Note: it's all just one array of bytes, I've just sectioned them up with brackets for readability.
import UIKit
import HealthKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
private let store = HKHealthStore()
private let falls = HKObjectType.quantityType(forIdentifier: .numberOfTimesFallen)!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
import UIKit
import HealthKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private let store = HKHealthStore()
private let falls = HKObjectType.quantityType(forIdentifier: .numberOfTimesFallen)!
private var lastAnchor: HKQueryAnchor?
in XCUIApplication:
Class Methods:
+ (id) keyPathsForValuesAffectingIsApplicationStateKnown; (0x102b2c73d)
+ (id) keyPathsForValuesAffectingRunning; (0x102b2c80a)
+ (id) keyPathsForValuesAffectingSuspended; (0x102b2c847)
+ (id) keyPathsForValuesAffectingBackground; (0x102b2c884)
+ (id) keyPathsForValuesAffectingForeground; (0x102b2c8c1)
+ (id) keyPathsForValuesAffectingState; (0x102b2c7b0)
+ (id) new; (0x102b2b376)
Properties:
in UIApplication:
Class Methods:
+ (Class) safeCategoryBaseClass; (0x104162e9b)
+ (BOOL) _isSerializableAccessibilityElement; (0x1041635a8)
+ (id) sharedApplication; (0x7fff478435d5)
+ (long) _classicMode; (0x7fff4785c371)
+ (BOOL) _isClassic; (0x7fff4786d3a0)
+ (BOOL) shouldMakeUIForDefaultPNG; (0x7fff478440b7)
+ (BOOL) isRunningInStoreDemoMode; (0x7fff47844021)
+ (BOOL) _isSystemUIService; (0x7fff47845961)
@KaneCheshire
KaneCheshire / XCUIElement private methods and properties
Created November 7, 2019 09:41
All of the methods and properties (including private) of an XCUIElement in iOS 13.2/Xcode11.2.1
iVars:
_safeQueryResolutionEnabled (BOOL): NO
_query (XCUIElementQuery*): <XCUIElementQuery: 0x6000023b28a0>
_lastSnapshot (XCElementSnapshot*): nil
Class Methods:
+ (id) standardAttributeNames; (0x10ef39e67)
+ (BOOL) _isInvalidEventDuration:(double)arg1; (0x10ef8b940)
+ (BOOL) _dispatchEventWithEventBuilder:(^block)arg1 eventSynthesizer:(id)arg2 inContext:(id)arg3 withSnapshot:(id)arg4 applicationSnapshot:(id)arg5 process:(id)arg6 error:(id*)arg7; (0x10ef8b961)
@KaneCheshire
KaneCheshire / MockDecoder.swift
Created October 23, 2019 07:59
Example on how to mock JSONDecoder for tests
final class MockDecoder: Decoder {
var valuesForKeys: [String: Decodable] = [:]
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> where Key: CodingKey {
return KeyedDecodingContainer(MockContainer(valuesForKeys: valuesForKeys))
}
let codingPath: [CodingKey] = []
let userInfo: [CodingUserInfoKey: Any] = [:]
@KaneCheshire
KaneCheshire / SimEnv_Xcode11.json
Created September 26, 2019 07:44
Output for the environment variables available on iOS simulators using `ProcessInfo.processInfo.environment`
{
"CA_ASSERT_MAIN_THREAD_TRANSACTIONS": "0",
"CA_DEBUG_TRANSACTIONS": "0",
"CFFIXED_USER_HOME": "/Users/kanecheshire/Library/Developer/XCTestDevices/2F7BBCEE-1020-4C33-9740-DCB7640911A4/data/Containers/Data/Application/4F2F5AA6-B639-45DE-9851-904569336CC4",
"CUPS_SERVER": "/private/tmp/com.apple.launchd.rz10bWAeQ8/Listeners",
"DYLD_FALLBACK_FRAMEWORK_PATH": ":",
"DYLD_FALLBACK_LIBRARY_PATH": "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib",
"DYLD_FRAMEWORK_PATH": "/Users/kanecheshire/Library/Developer/Xcode/DerivedData/Retryable-fezwrtdwmzupungrxeqznlnohxjl/Build/Products/Debug-iphonesimulator:/Users/kanecheshire/Library/Developer/Xcode/DerivedData/Retryable-fezwrtdwmzupungrxeqznlnohxjl/Build/Products/Debug-iphonesimulator",
"DYLD_LIBRARY_PATH": "/Users/kanecheshire/Library/Developer/Xcode/DerivedData/Retryable-fezwrtdwmzupungrxeqznlnohxjl/Build/Products/Debug-iphones