-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathBuildSettings+Live.swift
49 lines (45 loc) · 1.99 KB
/
BuildSettings+Live.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Foundation
extension BuildSettings {
static let live = BuildSettings(bundle: .app)
init(bundle: Bundle) {
brand = AppBrand(rawValue: bundle.infoValue(forKey: "WPAppBrand"))!
pushNotificationAppID = bundle.infoValue(forKey: "WPPushNotificationAppID")
appGroupName = bundle.infoValue(forKey: "WPAppGroupName")
appKeychainAccessGroup = bundle.infoValue(forKey: "WPAppKeychainAccessGroup")
eventNamePrefix = bundle.infoValue(forKey: "WPEventNamePrefix")
explatPlatform = bundle.infoValue(forKey: "WPExplatPlatform")
itunesAppID = bundle.infoValue(forKey: "WPItunesAppID")
}
}
private extension Bundle {
func infoValue<T>(forKey key: String) -> T where T: LosslessStringConvertible {
guard let object = object(forInfoDictionaryKey: key) else {
fatalError("missing value for key: \(key)")
}
switch object {
case let value as T:
return value
case let string as String:
guard let value = T(string) else { fallthrough }
return value
default:
fatalError("unexpected value: \(object) for key: \(key)")
}
}
}
private extension Bundle {
/// Returns the `Bundle` for the host `.app`.
///
/// - If this is called from code already located in the main app's bundle or from a Pod/Framework,
/// this will return the same as `Bundle.main`, aka the bundle of the app itself.
/// - If this is called from an App Extension (Widget, ShareExtension, etc), this will return the bundle of the
/// main app hosting said App Extension (while `Bundle.main` would return the App Extension itself)
static let app: Bundle = {
var url = Bundle.main.bundleURL
while url.pathExtension != "app" && url.lastPathComponent != "/" {
url.deleteLastPathComponent()
}
guard let appBundle = Bundle(url: url) else { fatalError("Unable to find the parent app bundle") }
return appBundle
}()
}