Skip to content

Instantly share code, notes, and snippets.

Avatar

Kyle Sherman drumnkyle

View GitHub Profile
@drumnkyle
drumnkyle / ErasedSubjects.swift
Last active Mar 11, 2020
Erasing Combine Subjects Property Wrapper
View ErasedSubjects.swift
#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 May 25, 2020
SwiftUI Preview Helpers for Most Edge Cases
View AllComponentPreviews.swift
/**
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 Feb 18, 2020
All Component Previews Example
View allComponentPreviews.swift
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()
View multiplePreviews.swift
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView()
.environment(\.sizeCategory,
.accessibilityLarge)
ContentView()
.environment(\.sizeCategory,
.accessibilityExtraExtraLarge)
@drumnkyle
drumnkyle / simplePreview.swift
Created Jan 23, 2020
SwiftUI Previews for All Configurations
View simplePreview.swift
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView(title: "Small Title")
ContentView(title: "Longer Title to Make Sure It Works")
}
}
}
View cleanup_files.sh
#!/bin/bash
rm "compile_commands.json"
rm "xcodebuild.log"
@drumnkyle
drumnkyle / ButtonScrollPerformanceTest.m
Last active Feb 12, 2019
Full Scroll Performance Framework
View ButtonScrollPerformanceTest.m
/*
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 Aug 17, 2018
ButtonScrollPerformanceTest
View ButtonScrollPerformanceTest.m
#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 Aug 17, 2018
iOS Device Usage
View usage.h
#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 Aug 17, 2018
KSScrollPerformanceDetector
View KSScrollPerformanceDetector.h
#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;