From SwiftTube Smart Debugging Talk 2018 and Advanced Debugging Techniques
brew install chisel
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 |
From SwiftTube Smart Debugging Talk 2018 and Advanced Debugging Techniques
brew install chisel
// | |
// NSManagedObjectExtension.swift | |
// | |
// Created by Karim Abou Zeid on 10.06.18. | |
// Copyright © 2018 Karim Abou Zeid Software. All rights reserved. | |
// | |
import CoreData | |
extension NSManagedObject { |
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 | |
} |
// 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) |
//How to URL Encode string | |
CFURLCreateStringByAddingPercentEscapes(nil, str, nil, "!*'();:@&=+$,/?%#[]\" ", kCFStringEncodingASCII) |
import Foundation | |
class Box<T> { | |
let unbox: T | |
init(_ value: T) { self.unbox = value } | |
} | |
struct Notification<A> { | |
let name: String | |
} |