Skip to content

Instantly share code, notes, and snippets.

View perlguy99's full-sized avatar

Brent Michalski perlguy99

  • Senior iOS Engineer
  • St. Louis, MO
View GitHub Profile
@rileytestut
rileytestut / ExportIPA.swift
Last active March 4, 2024 09:36
Export Swift Playgrounds .ipa
import Foundation
// Export running app as .ipa, then return path to exported file.
// Returns String because app crashes when returning URL from async function for some reason...
func exportIPA() async throws -> String
{
// Path to app bundle
let bundleURL = Bundle.main.bundleURL
// Create Payload/ directory
@perlguy99
perlguy99 / iOS_Debugging.md
Last active July 28, 2021 07:21
Debugging Hints, Tips, Tricks
@kabouzeid
kabouzeid / NSManagedObjectExtension.swift
Last active September 9, 2020 17:16
Simple extension to observe CoreData NSManagedObjects, behaves like the observe function in Realm.
//
// NSManagedObjectExtension.swift
//
// Created by Karim Abou Zeid on 10.06.18.
// Copyright © 2018 Karim Abou Zeid Software. All rights reserved.
//
import CoreData
extension NSManagedObject {
@cprovatas
cprovatas / Data+PrettyPrint.swift
Created May 23, 2018 15:52
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active January 15, 2023 13:03
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
// Swift's untyped errors are a goddam PiTA. Here's the pattern I use to try to work around this.
// The goal is basically to try to guarantee that every throwing function in the app throws an
// ApplicationError instead of some unknown error type. We can't actually enforce this statically
// But by following this convention we can simplify error handling
enum ApplicationError: Error, CustomStringConvertible {
// These are application-specific errors that may need special treatment
case specificError1
case specificError2(SomeType)
@ddunbar
ddunbar / xcbuild-debugging-tricks.md
Last active April 13, 2024 15:41
Xcode new build system debugging tricks

New Build System Tricks

Command Line

alias xcbuild=$(xcode-select -p)/../SharedFrameworks/XCBuild.framework/Versions/A/Support/xcbuild
# THIS DOESNT WORK YET: xcbuild openIDEConsole  # … then switch to Xcode ➡️
xcbuild showSpecs
xcbuild build <foo.pif> [—target <target>]
//How to URL Encode string
CFURLCreateStringByAddingPercentEscapes(nil, str, nil, "!*'();:@&=+$,/?%#[]\" ", kCFStringEncodingASCII)
@chriseidhof
chriseidhof / TypedNotifications.swift
Created January 26, 2015 14:41
Typed Notifications
import Foundation
class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
}
struct Notification<A> {
let name: String
}