mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-17 18:53:40 +01:00
[Shared] Adds @UserInfoValue property wrapper for ALTLocalizedErrors
ALTLocalizedErrors now automatically include all properties annotated with @UserInfoValue in userInfo when bridged to NSError.
This commit is contained in:
38
Shared/Errors/UserInfoValue.swift
Normal file
38
Shared/Errors/UserInfoValue.swift
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// UserInfoValue.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/2/23.
|
||||
// Copyright © 2023 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol UserInfoValueProtocol<Value>
|
||||
{
|
||||
associatedtype Value
|
||||
|
||||
var key: String? { get }
|
||||
var wrappedValue: Value { get }
|
||||
}
|
||||
|
||||
@propertyWrapper
|
||||
public struct UserInfoValue<Value>: UserInfoValueProtocol
|
||||
{
|
||||
public let key: String?
|
||||
public var wrappedValue: Value
|
||||
|
||||
// Necessary for memberwise initializers to work as expected
|
||||
// https://github.com/apple/swift-evolution/blob/main/proposals/0258-property-wrappers.md#memberwise-initializers
|
||||
public init(wrappedValue: Value)
|
||||
{
|
||||
self.wrappedValue = wrappedValue
|
||||
self.key = nil
|
||||
}
|
||||
|
||||
public init(wrappedValue: Value, key: String)
|
||||
{
|
||||
self.wrappedValue = wrappedValue
|
||||
self.key = key
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user