.font不可转换为.font

时间:2019-07-11 22:36:05

标签: swift swiftui

我正在学习Swift UI教程,而教练没有遇到此错误。 .font错误仅在第一个Vstack中出现1次,而第二次则没有问题。

import SwiftUI

struct ContentView : View {
    @State var title: String = ""
    @State var rating = 3.0
    @State var seen = false

    var body: some View {
        List {
            Section {
                VStack(alignment: .leading) {
                    Text("Title")
                    .font(.subheadline)       
                    .foregroundColor(.grey)
                TextField($title)
                }
            }
            Section {
                VStack(alignment: .leading) {
                    Text("Rating").font(.subheadline)
                    .foregroundColor(.gray)
                    HStack {
                        Spacer()
                    Text(String(repeating:"*", count:Int(rating)))
                Slider(value: $rating, from: 1.0, through: 5.0, by: 
        1.0).font(.title)
                        .foregroundColor(.yellow)
                    Spacer()
                    }
                }
            }

         }.listStyle(.grouped)
       }
    }

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif
Tracker/ContentView.swift:22:28: 'Font' is not convertible to 
'Font?'

1 个答案:

答案 0 :(得分:5)

这是一个误导性错误。该问题与def sign_in(): try: browser.find_element_by_xpath('//button/span[text()= "SIGN IN"]').click() return True except NoSuchElementException: return False 没有任何关系。问题是您有错字:

Font

Text("Title") .font(.subheadline) .foregroundColor(.grey) 应该是foregroundColor,而不是.gray