【问题标题】:Cannot find type SwiftUI 'Color' in scope在范围内找不到类型 SwiftUI 'Color'
【发布时间】:2020-09-28 21:01:33
【问题描述】:

我为UIColor 添加了一个扩展,具有到SwiftUI 的Color 的快速转换功能。 很简单:

import Foundation
import SwiftUI
import UIKit

@available(iOS 13, macOS 10.15, *)
public extension UIColor {
    
    /// Converts the platform specific color object to a swiftUI color struct. 
    /// - Returns: Equivalent SwiftUI color
    func psoColor() -> Color {
        return Color(self)
    }
}

编译器在 release 模式下引发错误:'Cannot find type 'Color' in scope'。 但是在 debug 模式下编译时,我没有收到该错误。

它所在的框架最初是在 obj-c 中开发的,但自 Swift 3 以来我一直在添加 Swift 类,没有任何问题。我目前正在使用带有 Xcode 12.0 的 Swift 5.3。部署目标设置为 iOS 10.0,这就是我添加 @available 装饰器的原因。

我不知道如何调试它,非常感谢任何帮助。

【问题讨论】:

    标签: swift xcode swiftui


    【解决方案1】:

    问题在于架构, swiftUI 不适用于 armv7。在发布模式下构建时,它包括 arm64 和 armv7。

    参考: SwiftUI - “Use of undeclared type xxx” on deployment targets below or equal to iOS 10

    【讨论】:

      【解决方案2】:

      通过添加 import UIkit 您的问题将在 swift 5 中解决

      【讨论】:

      • 如果你读了这篇文章,你可以清楚地看到我已经尝试过了
      猜你喜欢
      • 2023-01-26
      • 2020-12-31
      • 1970-01-01
      • 1970-01-01
      • 2021-09-24
      • 2021-09-21
      • 2021-08-01
      • 2022-01-16
      • 2021-08-03
      相关资源
      最近更新 更多