我有一个显示网络视图的基本列表。我想添加一个在网页加载时显示的活动指示器。这是我创建的代码。
import SwiftUI
import WebKit
struct WebView: UIViewRepresentable {
var url: String
// makeUIView func
func makeUIView(context: Context) -> WKWebView {
guard let url = URL(string: self.url) else {
return WKWebView()
}
let request = URLRequest(url: url)
let wkWebView = WKWebView()
wkWebView.load(request)
return wkWebView
}
// updateUIView func
func updateUIView(_ uiView: WKWebView, context: Context) {
}
}
struct WebView_Preview: PreviewProvider {
static var previews: some View {
WebView(url: "https://www.google.com")
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你!
我正在尝试制作一个复利计算器应用程序,当我返回复利公式时出现此错误 -> Initializer 'init(_:)' 要求 'Decimal' 符合 'BinaryInteger'
执行复利公式时出现错误: return balance * pow((1 + rate / 100), Int(mounths))
struct CompoundView: View {
@State var accountBalance: Decimal?
@State var percentagePerMounth: Decimal?
@State var numberOfMounths: Decimal?
@State var totalCompoundInterest = " "
var total: Decimal {
guard let balance = self.accountBalance, let rate = self.percentagePerMounth, let mounths = self.numberOfMounths else {
return 0
}
return balance * pow((1 + rate / 100), Int(mounths))
}
// Currency Formater
static var currencyFormatter: NumberFormatter { …Run Code Online (Sandbox Code Playgroud)