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
| class ViewController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| Task { | |
| // 1️⃣❓ UIViewController is in a MainActor context, so this Task | |
| // will inherit that, so the following pretend expensive call will | |
| // be on the main thread and likely block? | |
| ExpensiveOperationPerformer.doExpensiveLoopAndPrint() | |
| } |
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
| # Add this to a "Run Script" build phase in your app's main target, as the last step. | |
| # It will use the pluginkit command-line tool to force the plugin system on macOS to add your extensions to its database, making them available. | |
| # I made this specifically for widgets, but it should work for pretty much any extension type (appex bundle). | |
| find $CODESIGNING_FOLDER_PATH -name '*.appex' -exec pluginkit -a {} \; |
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 UIKit | |
| extension UITextField { | |
| /// Add a trailing placeholder label that tracks the text as it changes | |
| func addTrailingPlaceholder(_ placeholder: String) { | |
| let label = UILabel() | |
| label.text = placeholder | |
| label.alpha = 0.3 | |
| label.isHidden = true | |
| let container = UIView() |
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 | |
| // 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 |
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
| /// MIT License | |
| /// | |
| /// Copyright (c) 2021 Lukas Kubanek, Structured Path GmbH | |
| /// | |
| /// 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: |
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 2021 Kyle Hughes | |
| // | |
| // 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 portions of the | |
| // Software. | |
| // |
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
| // Excerpt from https://github.com/krzyzanowskim/CoreTextWorkshop | |
| // Licence BSD-2 clause | |
| // Marcin Krzyzanowski marcin@krzyzanowskim.com | |
| func getSizeThatFits(_ attributedString: NSAttributedString, maxWidth: CGFloat) -> CGSize { | |
| let framesetter = CTFramesetterCreateWithAttributedString(attributedString) | |
| let rectPath = CGRect(origin: .zero, size: CGSize(width: maxWidth, height: 50000)) | |
| let ctFrame = CTFramesetterCreateFrame(framesetter, CFRange(), CGPath(rect: rectPath, transform: nil), nil) |
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
| extension Locale { | |
| /// Returns an SF Symbol currency image that match's the device's current locale, for instance dollar in North America, Indian rupee in India, etc. | |
| func currencySFSymbol(filled: Bool, withConfiguration configuration: UIImage.Configuration? = nil) -> UIImage { | |
| // Default currency symbol will be the Animal Crossing Leaf coin to remain impartial to any specific country | |
| let defaultSymbol = UIImage(systemName: "leaf.circle\(filled ? ".fill" : "")")! | |
| guard let currencySymbolName = currencySymbolNameForSFSymbols() else { return defaultSymbol } | |
| let systemName = "\(currencySymbolName).circle\(filled ? ".fill" : "")" | |
| return UIImage(systemName: systemName, withConfiguration: configuration) ?? defaultSymbol |
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
| var content = UNMutableNotificationContent() | |
| content.title = "Title" | |
| content.subtitle = "Subtitle" | |
| content.body = "Text" | |
| content.sound = nil | |
| content.categoryIdentifier = "categoryName" | |
| var personNameComponents = PersonNameComponents() | |
| personNameComponents.nickname = "Sender Name" |
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
| extension Color { | |
| /// Return a random color | |
| static var random: Color { | |
| return Color( | |
| red: .random(in: 0...1), | |
| green: .random(in: 0...1), | |
| blue: .random(in: 0...1) | |
| ) | |
| } | |
| } |