mirror of
https://github.com/mas-cli/mas
synced 2024-11-26 21:40:19 +00:00
5be95132e9
for easy dependency injection
26 lines
753 B
Swift
26 lines
753 B
Swift
//
|
|
// MasAppLibrary.swift
|
|
// MasKit
|
|
//
|
|
// Created by Ben Chatelain on 12/27/18.
|
|
// Copyright © 2018 mas-cli. All rights reserved.
|
|
//
|
|
|
|
import CommerceKit
|
|
|
|
/// Utility for managing installed apps.
|
|
public class MasAppLibrary: AppLibrary {
|
|
/// CommerceKit's singleton manager of installed software.
|
|
private let softwareMap = CKSoftwareMap.shared()
|
|
|
|
public init() {}
|
|
|
|
/// Finds an app by ID from the set of installed apps
|
|
///
|
|
/// - Parameter appId: MAS ID for app.
|
|
/// - Returns: Software Product of app if found; nil otherwise.
|
|
public func installedApp(appId: UInt64) -> SoftwareProduct? {
|
|
let appId = NSNumber(value: appId)
|
|
return softwareMap.allProducts()?.first { $0.itemIdentifier == appId }
|
|
}
|
|
}
|