Skip to content

Commit

Permalink
Merge pull request #159 from JORDYMA-Link/BUG/#155
Browse files Browse the repository at this point in the history
[BUG] 1.0.6 QA 반영
  • Loading branch information
kimkyuchul authored Dec 11, 2024
2 parents 6a4f503 + 4c7bb51 commit 4d777ed
Show file tree
Hide file tree
Showing 14 changed files with 418 additions and 245 deletions.
17 changes: 14 additions & 3 deletions Projects/Core/Services/Sources/SocialLogin/AppleLogin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import AuthenticationServices

import Models

enum AppleErrorType: Error {
public enum AppleErrorType: Error {
case invalidToken
case invalidAuthorizationCode
case dismissASAuthorizationController
}

final class AppleLogin: NSObject, ASAuthorizationControllerDelegate {
Expand Down Expand Up @@ -76,8 +77,18 @@ final class AppleLogin: NSObject, ASAuthorizationControllerDelegate {
}
}

@MainActor
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
continuation?.resume(throwing: error)
continuation = nil
if let authError = error as? ASAuthorizationError {
switch authError.code {
case .canceled:
continuation?.resume(throwing: AppleErrorType.dismissASAuthorizationController)
continuation = nil

default:
continuation?.resume(throwing: authError)
continuation = nil
}
}
}
}
189 changes: 96 additions & 93 deletions Projects/Core/Services/Sources/UserDefaults/UserDefaultsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,112 +11,115 @@ import Foundation
import ComposableArchitecture

public struct UserDefaultsClient {
public enum UserDefaultsKey: String {
case fcmToken
case isPopGestureEnabled
case recentSearches
case latestUnsavedSummaryFeedId
public enum UserDefaultsKey: String {
case isFirstLaunch
case fcmToken
case isPopGestureEnabled
case recentSearches
case latestUnsavedSummaryFeedId
}

public var string: @Sendable (_ forKey: UserDefaultsKey, _ default: String) -> String
public var integer: @Sendable (_ forKey: UserDefaultsKey, _ default: Int) -> Int
public var bool: @Sendable (_ forKey: UserDefaultsKey, _ default: Bool) -> Bool
public var float: @Sendable (_ forKey: UserDefaultsKey, _ default: Float) -> Float
public var double: @Sendable (_ forKey: UserDefaultsKey, _ default: Double) -> Double
public var data: @Sendable (_ forKey: UserDefaultsKey, _ default: Data) -> Data
public var stringArray: @Sendable (_ forKey: UserDefaultsKey, _ default: [String]) -> [String]
public var object: @Sendable (_ forKey: UserDefaultsKey, _ default: Any) -> Any
public var set: @Sendable (_ value: Any, _ forKey: UserDefaultsKey) -> Void
public var removeObject: @Sendable (_ forKey: UserDefaultsKey) -> Void
public var reset: @Sendable () -> Void

public func codableObject<T: Codable>(_ type: T.Type, forKey key: String, defaultValue: T) -> T {
guard let data = UserDefaults.standard.data(forKey: key) else {
return defaultValue
}

public var string: @Sendable (_ forKey: UserDefaultsKey, _ default: String) -> String
public var integer: @Sendable (_ forKey: UserDefaultsKey, _ default: Int) -> Int
public var bool: @Sendable (_ forKey: UserDefaultsKey, _ default: Bool) -> Bool
public var float: @Sendable (_ forKey: UserDefaultsKey, _ default: Float) -> Float
public var double: @Sendable (_ forKey: UserDefaultsKey, _ default: Double) -> Double
public var data: @Sendable (_ forKey: UserDefaultsKey, _ default: Data) -> Data
public var stringArray: @Sendable (_ forKey: UserDefaultsKey, _ default: [String]) -> [String]
public var object: @Sendable (_ forKey: UserDefaultsKey, _ default: Any) -> Any
public var set: @Sendable (_ value: Any, _ forKey: UserDefaultsKey) -> Void
public var removeObject: @Sendable (_ forKey: UserDefaultsKey) -> Void
public var reset: @Sendable () -> Void

public func codableObject<T: Codable>(_ type: T.Type, forKey key: String, defaultValue: T) -> T {
guard let data = UserDefaults.standard.data(forKey: key) else {
return defaultValue
}

let decoder = JSONDecoder()
do {
let object = try decoder.decode(type, from: data)
return object
} catch {
print("Failed to decode \(type) from UserDefaults with key \(key): \(error)")
return defaultValue
}
let decoder = JSONDecoder()
do {
let object = try decoder.decode(type, from: data)
return object
} catch {
print("Failed to decode \(type) from UserDefaults with key \(key): \(error)")
return defaultValue
}
public func setCodable<T: Codable>(_ value: T, forKey key: String) {
let encoder = JSONEncoder()
do {
let data = try encoder.encode(value)
UserDefaults.standard.set(data, forKey: key)
} catch {
print("Failed to encode \(value) for key \(key): \(error)")
}
}

public func setCodable<T: Codable>(_ value: T, forKey key: String) {
let encoder = JSONEncoder()
do {
let data = try encoder.encode(value)
UserDefaults.standard.set(data, forKey: key)
} catch {
print("Failed to encode \(value) for key \(key): \(error)")
}
}
}

extension UserDefaultsClient: DependencyKey {
static func userDefaultsObject<T>(_ type: T.Type, forKey key: String, defaultValue: T) -> T {
guard let value = UserDefaults.standard.object(forKey: key) as? T else {
return defaultValue
}

return value
static func userDefaultsObject<T>(_ type: T.Type, forKey key: String, defaultValue: T) -> T {
guard let value = UserDefaults.standard.object(forKey: key) as? T else {
return defaultValue
}

return value
}

static func userDefaultsArray<T>(_ type: T.Type, forKey key: String, defaultValue: T) -> T {
guard let value = UserDefaults.standard.array(forKey: key) as? T else {
return defaultValue
guard let value = UserDefaults.standard.array(forKey: key) as? T else {
return defaultValue
}

return value
}

public static var liveValue: UserDefaultsClient {
return Self(
string: { key, defaultValue in
return userDefaultsObject(String.self, forKey: key.rawValue, defaultValue: defaultValue)
},
integer: { key, defaultValue in
return userDefaultsObject(Int.self, forKey: key.rawValue, defaultValue: defaultValue)
},
bool: { key, defaultValue in
return userDefaultsObject(Bool.self, forKey: key.rawValue, defaultValue: defaultValue)
},
float: { key, defaultValue in
return userDefaultsObject(Float.self, forKey: key.rawValue, defaultValue: defaultValue)
},
double: { key, defaultValue in
return userDefaultsObject(Double.self, forKey: key.rawValue, defaultValue: defaultValue)
},
data: { key, defaultValue in
return userDefaultsObject(Data.self, forKey: key.rawValue, defaultValue: defaultValue)
},
stringArray: { key, defaultValue in
return userDefaultsArray([String].self, forKey: key.rawValue, defaultValue: defaultValue)
},
object: { key, defaultValue in
return UserDefaults.standard.object(forKey: key.rawValue) ?? defaultValue
},
set: { value, key in
UserDefaults.standard.set(value, forKey: key.rawValue)
},
removeObject: { key in
UserDefaults.standard.removeObject(forKey: key.rawValue)
},
reset: {
for key in UserDefaults.standard.dictionaryRepresentation().keys {
if key != UserDefaultsKey.isFirstLaunch.rawValue {
UserDefaults.standard.removeObject(forKey: key.description)
}
}
}

return value
)
}

public static var liveValue: UserDefaultsClient {
return Self(
string: { key, defaultValue in
return userDefaultsObject(String.self, forKey: key.rawValue, defaultValue: defaultValue)
},
integer: { key, defaultValue in
return userDefaultsObject(Int.self, forKey: key.rawValue, defaultValue: defaultValue)
},
bool: { key, defaultValue in
return userDefaultsObject(Bool.self, forKey: key.rawValue, defaultValue: defaultValue)
},
float: { key, defaultValue in
return userDefaultsObject(Float.self, forKey: key.rawValue, defaultValue: defaultValue)
},
double: { key, defaultValue in
return userDefaultsObject(Double.self, forKey: key.rawValue, defaultValue: defaultValue)
},
data: { key, defaultValue in
return userDefaultsObject(Data.self, forKey: key.rawValue, defaultValue: defaultValue)
},
stringArray: { key, defaultValue in
return userDefaultsArray([String].self, forKey: key.rawValue, defaultValue: defaultValue)
},
object: { key, defaultValue in
return UserDefaults.standard.object(forKey: key.rawValue) ?? defaultValue
},
set: { value, key in
UserDefaults.standard.set(value, forKey: key.rawValue)
},
removeObject: { key in
UserDefaults.standard.removeObject(forKey: key.rawValue)
},
reset: {
for key in UserDefaults.standard.dictionaryRepresentation().keys {
UserDefaults.standard.removeObject(forKey: key.description)
}
}
)
}
}

public extension DependencyValues {
var userDefaultsClient: UserDefaultsClient {
get { self[UserDefaultsClient.self] }
set { self[UserDefaultsClient.self] = newValue }
}
var userDefaultsClient: UserDefaultsClient {
get { self[UserDefaultsClient.self] }
set { self[UserDefaultsClient.self] = newValue }
}
}
Loading

0 comments on commit 4d777ed

Please sign in to comment.