Skip to content

Instantly share code, notes, and snippets.

@robertmryan
robertmryan / ExportMPMediaItem.swift
Last active November 6, 2023 06:46
Export MPMediaItem to file in Documents
/// Export MPMediaItem to temporary file.
///
/// - Parameters:
/// - assetURL: The `assetURL` of the `MPMediaItem`.
/// - completionHandler: Closure to be called when the export is done. The parameters are a boolean `success`, the `URL` of the temporary file, and an optional `Error` if there was any problem. The parameters of the closure are:
///
/// - fileURL: The `URL` of the temporary file created for the exported results.
/// - error: The `Error`, if any, of the asynchronous export process.
func export(_ assetURL: URL, completionHandler: @escaping (_ fileURL: URL?, _ error: Error?) -> ()) {
@filsv
filsv / WatchSessionManager.swift
Last active April 8, 2023 21:33
WatchConnectivity Singleton (Swift 5+, iOS+WatchOS Targets) + How to (comment below)
import WatchConnectivity
class WatchSessionManager: NSObject, WCSessionDelegate {
static let sharedManager = WatchSessionManager()
private override init() {
super.init()
}
private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil