【问题标题】:'Font' is not convertible to 'Font?' in SwiftUI Tutorial“字体”不能转换为“字体?”在 SwiftUI 教程中
【发布时间】:2019-11-13 18:55:43
【问题描述】:

在 Apple SwiftUI 教程中,我刚刚遇到了一些错误。

https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation

在本教程中,在第 8、9、10 步之后,出现错误。

这是我写的:

import SwiftUI

struct LandmarkDetail : View {

var landmark: Landmark

var body: some View {
    VStack {

        MapView(landmark.locationCoordinate)
            .edgesIgnoringSafeArea(.top)
            .frame(height: 300)


        CircleImage(landmark.image(forSize: 50)).offset(y: -130)
        .padding(.bottom, -130)

        VStack(alignment: .leading){
            Text(landmark.name)
                .font(.title)

            HStack{
                Text(landmark.park)
                    .font(.subheadline)
                Spacer()
                Text(landmark.state)
                    .font(.subheadline)
            }
        }
        .padding(30)

        Spacer()
        }
}

这段代码运行良好,没有任何错误。

但是将一些常量更改为变量后,就会出现这些错误。

我曾多次尝试重新启动 Xcode,但它不起作用。

这有什么问题?

以下是苹果写的:

var body: some View {
    VStack {
        MapView(coordinate: landmark.locationCoordinate)
            .frame(height: 300)

        CircleImage(image: landmark.image(forSize: 250))
            .offset(y: -130)
            .padding(.bottom, -130)

        VStack(alignment: .leading) {
            Text(landmark.name)
                .font(.title)

            HStack(alignment: .top) {
                Text(landmark.park)
                    .font(.subheadline)
                Spacer()
                Text(landmark.state)
                    .font(.subheadline)
            }
        }
        .padding()

        Spacer()
    }

Xcode:版本 11.0 测试版 (11M336w)

【问题讨论】:

    标签: ios swiftui xcode11


    【解决方案1】:

    改变这两行,

            MapView(landmark.locationCoordinate)
                .edgesIgnoringSafeArea(.top)
                .frame(height: 300)
    
            CircleImage(landmark.image(forSize: 50)).offset(y: -130)
            .padding(.bottom, -130)
    

    到这里,

            MapView(coordinate: landmark.locationCoordinate)
                    .edgesIgnoringSafeArea(.top)
                    .frame(height: 300)
    
            CircleImage(image: landmark.image(forSize: 50)).offset(y: -130)
                    .padding(.bottom, -130)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-05
      • 2019-07-26
      • 1970-01-01
      • 2013-05-24
      • 2010-10-04
      • 2017-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多