У меня есть класс, который определен как Singleton, и я пытаюсь получить доступ к 2 функциям из этого класса, но я получаю ошибку, которая говорит, что класс не может быть найден, но когда я нажимаю Cmd + Click, я могу перейти к этому классу.
Я перезапускал xCode так много раз, также я пытался с xCode 10 и xCode 9 ... та же ошибка. Я не знаю, как это исправить.
Вот мой код:
// First Class
class BankAccount {
private init() {}
static let bankAccountKey = "Bank Account"
static let suiteName = "group.com.YourName"
// Function to set the balance for ShoppingLand Bank
static func setBalance(toAmount amount: Double) {
guard let defaults = UserDefaults(suiteName: suiteName) else { return }
defaults.set(amount, forKey: bankAccountKey)
defaults.synchronize()
}
// Function to check new updates about the balance of ShoppingLand Bank
static func checkBalance() -> Double? {
guard let defaults = UserDefaults(suiteName: suiteName) else { return nil }
defaults.synchronize()
let balance = defaults.double(forKey: bankAccountKey)
return balance
}
@discardableResult
static func withdraw(amount: Double) -> Double? {
guard let defaults = UserDefaults(suiteName: suiteName) else { return nil }
let balance = defaults.double(forKey: bankAccountKey)
let newBalance = balance - amount
setBalance(toAmount: newBalance)
return newBalance
}
@discardableResult
static func deposit(amount: Double) -> Double? {
guard let defaults = UserDefaults(suiteName: suiteName) else { return nil }
let balance = defaults.double(forKey: bankAccountKey)
let newBalance = balance + amount
setBalance(toAmount: newBalance)
return newBalance
}
}
// Second Class
import Intents
class IntentHandler: INExtension {}
extension IntentHandler: INSendPaymentIntentHandling {
func handle(intent: INSendPaymentIntent, completion: @escaping (INSendPaymentIntentResponse) -> Void) {
guard let amount = intent.currencyAmount?.amount?.doubleValue else {
completion(INSendPaymentIntentResponse(code: .failure, userActivity: nil))
return
}
BankAccount.withdraw(amount: amount)
completion(INSendPaymentIntentResponse(code: .success, userActivity: nil))
}
}
extension IntentHandler: INRequestPaymentIntentHandling {
func handle(intent: INRequestPaymentIntent, completion: @escaping (INRequestPaymentIntentResponse) -> Void) {
guard let amount = intent.currencyAmount?.amount?.doubleValue else {
completion(INRequestPaymentIntentResponse(code: .failure, userActivity: nil))
return
}
BankAccount.deposit(amount: amount)
completion(INRequestPaymentIntentResponse(code: .success, userActivity: nil))
}
}
Вот демоверсия:
http://recordit.co/NoXKlT3dw1
Спасибо за ваше время!