我正在嘗試創建一個小型社交媒體應用程式。到目前為止一切正常,但是當我試圖展示 a 的長度Array(這可以節省 aUser中的朋友ProfilView)時,我得到了錯誤"No exact matches in call to initializer"
Capsule()
.frame(width: 110, height: 30)
.offset(x: 40)
.foregroundColor(.blue)
.overlay(
HStack {
Image(systemName: "person.3.fill")
.foregroundColor(.white)
.position(x: 120, y: 15)
Text(appUser.friends.count)
.foregroundColor(.white)
.position(x: 35, y: 15)
.frame(width: 70, height: 30, alignment: .trailing)
}
)
class User: ObservableObject{
@Published var username: String = ""
@Published var name: String = ""
var password: String = ""
@Published var email: String = ""
@Published var beschreibung: String = ""
@Published var profilBild: UIImage?
@Published var friends = [User]()
init(_ username: String, _ password: String, _ email: String, _ name: String) {
self.username = username
self.password = password
self.email = email
self.name = name
}
}
uj5u.com熱心網友回復:
您正在嘗試發送Intto Text,它String在其初始化程式中需要 a 。
您可以將變數插入到String:
Text("\(appUser.friends.count)")
或者,您可以將 傳遞Int給String初始化程式:
Text(String(appUser.friends.count))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/435120.html
上一篇:如何使用@objc標記在代碼中為給定功能分配按鈕的操作?
下一篇:快速閱讀plist并處理錯誤
