问题描述
目前我正在学习 SwiftUI,但我面临着一个问题。编译器无法对表达式进行类型检查。
当我添加 Text(update.date) 时,一切就开始了。此外,更新是我创建的结构,其中数据成员之一是字符串类型的日期。
和代码长度有关系吗??
import SwiftUI
struct UpdateList: View {
var body: some View {
NavigationView {
List(updateData) { update in
NavigationLink(destination: Text(update.text)) {
vstack(alignment: .leading) {
Text(update.title)
.font(.system(size: 20,weight: .bold))
Text(update.text)
.font(.subheadline)
.lineLimit(2)
.foregroundColor(Color(#colorLiteral(red: 0.2549019754,green: 0.2745098174,blue: 0.3019607961,alpha: 1)))
Text(update.date) //all the errors occurred when typed this
.forgroundColor(.secondary)
}
}
}
.navigationBarTitle(Text("Updates"))
}
}
}
struct UpdateList_Previews: PreviewProvider {
static var previews: some View {
UpdateList()
}
}
struct Update: Identifiable{
var id = UUID()
var image: String
var title: String
var text: String
var date: String
}
let updateData: [Update] = [
Update(image: "Card1",title: "SwiftUI Advanced",text: "Take your app to App Store with advanced techniques like API data,packages and CMS",date: "JAN 1"),Update(image: "Card2",title: "WebFlow",text: "Design and animate a high converting landing page with advanced interations,payments and CMS",date: "OCT 17"),Update(image: "Card3",title: "ProtoPie",text: "Quickly Prototype advanced animations nd interactions for mobile and Web",date: "AUG 27"),Update(image: "Card4",title: "SwiftUI",text: "Learn how to code custom UI,animations and gestures and components in Xcode 11",date: "JUNE 26"),Update(image: "Card5",title: "Framer Playground",text: "Create powerful animations and interactions with Framer X code editor",date: "JUNE 11")
]
有什么建议吗??
这是快照:https://i.stack.imgur.com/LXOrH.png
提前致谢
解决方法
.forgroundColor(.secondary)
应该
.foregroundColor(.secondary)