Skip to content

Instantly share code, notes, and snippets.

View drumnkyle's full-sized avatar

Kyle Sherman drumnkyle

View GitHub Profile
@drumnkyle
drumnkyle / ErasedSubjects.swift
Last active March 11, 2020 23:58
Erasing Combine Subjects Property Wrapper
#if canImport(Combine)
import Combine
@propertyWrapper
/// Provides a property wrapper whose projected value is a `PassthroughSubject`, but
/// the wrapped value is just an `AnyPublisher`. This allows you to make a property with
/// availability declared for only iOS 13+ and hide the actual publisher.
public struct ErasedPassthroughSubject<Output, Failure: Error> {
private var value: Any?
@drumnkyle
drumnkyle / AllComponentPreviews.swift
Last active March 15, 2022 22:32
SwiftUI Preview Helpers for Most Edge Cases
/**
Copyright 2019 Kyle Sherman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
@drumnkyle
drumnkyle / allComponentPreviews.swift
Last active February 18, 2020 02:19
All Component Previews Example
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView(title: "Short String")
ContentView(title: """
This is a super long title \
spread across a single line
""")
}.allComponentPreviews()
@drumnkyle
drumnkyle / multiplePreviews.swift
Last active February 18, 2020 02:08
Multiple Previews
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView()
.environment(\.sizeCategory,
.accessibilityLarge)
ContentView()
.environment(\.sizeCategory,
.accessibilityExtraExtraLarge)
@drumnkyle
drumnkyle / simplePreview.swift
Created January 23, 2020 02:56
SwiftUI Previews for All Configurations
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView(title: "Small Title")
ContentView(title: "Longer Title to Make Sure It Works")
}
}
}
@drumnkyle
drumnkyle / cleanup_files.sh
Created December 10, 2018 18:57
OCLint Scripts
#!/bin/bash
rm "compile_commands.json"
rm "xcodebuild.log"
@drumnkyle
drumnkyle / ButtonScrollPerformanceTest.m
Last active February 12, 2019 14:54
Full Scroll Performance Framework
/*
The MIT License
Copyright (c) 2010-2018 Google, Inc. http://angularjs.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@drumnkyle
drumnkyle / ButtonScrollPerformanceTest.m
Last active August 17, 2018 18:46
ButtonScrollPerformanceTest
#import <XCTest/XCTest.h>
#import <KIF/KIF.h>
#import "KSScrollPerformanceDetector.h"
#import "usage.h"
// This is specifically chosen to be the right speed to not trigger optimizations
static const CGFloat KSScrollPerformanceTestsVelocity = -0.15f;
@interface ButtonScrollPerformanceTests : KIFTestCase <KSScrollPerformanceDetectorDelegate>
@drumnkyle
drumnkyle / usage.h
Last active August 28, 2024 07:24
iOS Device Usage
#ifndef usage_h
#define usage_h
#import <mach/mach.h>
double cpu_usage(int64_t *count);
float mem_usage();
#endif /* usage_h */
@drumnkyle
drumnkyle / KSScrollPerformanceDetector.h
Last active August 17, 2018 18:45
KSScrollPerformanceDetector
#import <Foundation/Foundation.h>
/**
These methods will not be called on the main thread. So,
if you will be doing anything with UIKit, ensure you dispatch back
to the main thread.
*/
@protocol KSScrollPerformanceDetectorDelegate<NSObject>
@optional
- (void)framesDropped:(NSInteger)framesDroppedCount cumulativeFramesDropped:(NSInteger)cumulativeFramesDropped cumulativeFrameDropEvents:(NSInteger)cumulativeFrameDropEvents;