This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: - Bad: "Use of protocol 'View' as a type must be written 'any View'" | |
| struct LeftRightView: View { | |
| let leftView: View | |
| let rightView: View | |
| var body: some View { | |
| HStack { | |
| leftView | |
| rightView |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // (c) Confusion Studios LLC and affiliates. Confidential and proprietary. | |
| import SwiftUI | |
| import UIKit | |
| class ViewController: UIViewController { | |
| override func viewDidLoad() { | |
| view.backgroundColor = .orange | |
| let swiftUIView = ContentView().asUIView |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// MultipartRequest by Dan Rosenstark | |
| /// Thanks to tinyurl.com/2qpbyh7v: this code is just a remix | |
| /// | |
| /// Steps to use | |
| /// 1. init | |
| /// 2. add form fields (if any) | |
| /// 3. add file data (if any) | |
| /// 4. grab the urlRequest and use it | |
| struct MultipartRequest { | |
| private let boundary = "Boundary-\(UUID().uuidString)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright 2022 Confusion Studios LLC | |
| // by Dan Rosenstark | |
| import Foundation | |
| /// Extension on DispatchQueue? for Testing | |
| /// If you don't have a DispatchQueue, run immediately (on current queue) | |
| extension Optional where Wrapped : DispatchQueue { | |
| public func asyncIfNotNil(execute block: @escaping ()->()) { | |
| if let self = self { | |
| self.async(execute: block) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "NSArray+Filter.h" | |
| @implementation NSArray (Filter) | |
| - (NSArray *) filteredArrayUsingBlock:(BOOL (^)(id obj))block { | |
| NSIndexSet *const filteredIndexes = [self indexesOfObjectsPassingTest:^BOOL (id _Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) { | |
| return block(obj); | |
| }]; | |
| return [self objectsAtIndexes:filteredIndexes]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| func permute(_ s: String) -> [String] { | |
| var arr = Array(s) | |
| var permutations = [[Character]]() | |
| permute(&arr, 0, &permutations) | |
| return permutations.map { String($0) } | |
| } | |
| func permute<T>(_ arr: inout [T], _ k: Int, _ result: inout [[T]]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # swiftWatchAndRun | |
| if [ $# -ne 1 ]; then | |
| echo "Use like this:" | |
| echo " $0 filename-to-watch" | |
| exit 1 | |
| fi | |
| if which fswatch >/dev/null; then | |
| echo "Watching swift file $1" | |
| while true; do fswatch --one-event $1 >/dev/null && echo "----------------"; echo `date +"%m-%d-%y %I:%M%p"`; echo "----------------" && swift $1; sleep 0.1; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| pbpaste > /tmp/shellpaste.sh | |
| echo "Execute this?" | |
| cat /tmp/shellpaste.sh | |
| echo | |
| read -p "Press enter to run it..." | |
| bash /tmp/shellpaste.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Run with: | |
| /// swift -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks xctest-in-repl.swift | |
| import Foundation | |
| import XCTest | |
| class ATest : XCTestCase { | |
| func testIt() { | |
| print("Oh yeah, it's on") | |
| XCTAssertTrue(false, "That needed to be true!") | |
| } |