Tested with macOS Ventura and xcode 14.
Files can be added by:
This is the easy way but image/video files are always added to the Photos app. Other kind of files like PDF are added to the Files app.
public extension Array { | |
/// Adds the elements of a sequence to the end of the array and returns a copy of it. | |
/// | |
/// This example creates a new array containing the elements of a | |
/// `Range<Int>` instance added to an array of integers | |
/// | |
/// let array = [1, 2, 3, 4, 5] | |
/// let numbers = array.appending(contentsOf: 10...15) | |
/// print(numbers) |
import SwiftUI | |
public struct MarkdownLinkView: View { | |
@State private var url: URL? | |
public var body: some View { | |
VStack(spacing: 20) { | |
Text(""" | |
**Plain text**: | |
[This is a tappable link](https://www.google.com) |
# Credits: https://in-thread.sonic-pi.net/t/demo-of-experimental-ableton-link-with-sonic-pi/5869/28 | |
# Call beat_fix with desired quantum just before defining your loops | |
use_bpm :link | |
sched_time = 0.5 | |
$latency = 0 + sched_time*1000.00 | |
def beat_fix(quantum=4) | |
diff = @tau_api.link_current_time_and_beat(false)[1] % quantum | |
x = ((quantum-diff) + 0 - rt($latency/1000.0)) % quantum |
import XCTest | |
func XCTAssertEmpty<T>(_ expression: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, line: UInt = #line) where T : Collection { | |
XCTAssertTrue(try expression().isEmpty, message(), file: file, line: line) | |
} | |
func XCTAssertNotEmpty<T>(_ expression: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, line: UInt = #line) where T : Collection { | |
XCTAssertFalse(try expression().isEmpty, message(), file: file, line: line) | |
} |
// Playground to showcase AnyCancellable instances are not automatically released upon completion if they're stored with the `store` function | |
import Combine | |
class LongLivedObject { | |
private(set) var bag = Set<AnyCancellable>() | |
func callCombineOperation() { | |
[1,2,3].publisher.sink { | |
print("completed: \($0)") | |
} receiveValue: { |
// Credits: https://onmyway133.com/posts/how-to-use-foreach-with-indices-in-swiftui/ | |
import SwiftUI | |
func ForEachWithIndex<Data: RandomAccessCollection, Content: View>( | |
_ data: Data, | |
@ViewBuilder content: @escaping (Data.Index, Data.Element) -> Content) | |
-> some View where Data.Element: Identifiable, Data.Element: Hashable { | |
ForEach(Array(zip(data.indices, data)), id: \.1) { index, element in | |
content(index, element) |
#if targetEnvironment(simulator) | |
let isRunningOnSimulator = true | |
#else | |
let isRunningOnSimulator = false | |
#endif |
// From: https://www.avanderlee.com/swift/async-await/ | |
// More info on @available: https://www.avanderlee.com/swift/available-deprecated-renamed/ | |
@available(*, deprecated, renamed: "fetchImages()") | |
func fetchImages(completion: @escaping (Result<[UIImage], Error>) -> Void) { ... } |
// Taken from Apple's App Dev Training: https://developer.apple.com/tutorials/app-dev-training/ | |
/// This color is either black or white, whichever is more accessible when viewed against the scrum color. | |
var accessibleFontColor: Color { | |
var red: CGFloat = 0 | |
var green: CGFloat = 0 | |
var blue: CGFloat = 0 | |
UIColor(self).getRed(&red, green: &green, blue: &blue, alpha: nil) | |
return isLightColor(red: red, green: green, blue: blue) ? .black : .white | |
} |