UIColor(named :)在iOS 11.0-11.2上始终返回nil [英] UIColor(named:) always returns nil on iOS 11.0-11.2

查看:179
本文介绍了UIColor(named :)在iOS 11.0-11.2上始终返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从我的自定义调色板返回UIColor的类.我以编程方式调用此函数,但是当我在iOS 11上对其进行测试时,它总是返回nil结果...我在多个设备和OS版本11.0、11.0.1、11.2上尝试了此操作,所有这些都返回了nil.但是,只要我在> iOS 12上运行它们,它就会始终返回正确的颜色.

I have a class that returns a UIColor from my custom palette. I call this programmatically but when I tested it on iOS 11 it always returns a nil result... I tried this on multiple devices and OS versions 11.0, 11.0.1, 11.2 and all of them returns nil. But as soon as I run them on >iOS 12 it always returns a correct color.

var color: UIColor? {
    switch self {
    case .darkIndigo: return UIColor(named: "darkIndigo")
    case .lightNavy: return UIColor(named: "lightNavy")
    case .cobalt: return UIColor(named: "cobalt")
    }
}

我最近更改了该应用程序的捆绑软件ID ...,这使我认为这与使用多个捆绑软件时UIImage存在的类似问题有关.尤其是当我收到错误消息

I have recently changed my bundle ID for the app... and this makes me think that it has something to do with the similar problem that UIImage has when multiple bundles are used. Especially when I get the error message

警告:无法从以下任何捆绑包中解析名为"darkIndigo"的颜色:

WARNING: Unable to resolve the color named "darkIndigo" from any of the following bundles:

但是应该如何解决?我是否应该手动删除整个资产目录并将其重新添加?

But how is this supposed to be resolved? Should I just manually remove the whole asset catalogue and add them back?

推荐答案

这是Xcode中的错误,已在新的GM Seed 2(11A420a)中修复.

This was a bug in Xcode and its fixed in the new GM Seed 2 (11A420a).

我也遇到了这个问题.我当时在使用Xcode 11 beta 6和命令行工具11.0.

I encountered this issue as well. I was using Xcode 11 beta 6, with Command Line Tools 11.0.

我通过切换到Xcode 10.2.1和命令行工具10.2.1进行了解决,并清理了&再次建造.

I solved it by switching to Xcode 10.2.1 and Command Line Tools 10.2.1, cleaning & building again.

这篇关于UIColor(named :)在iOS 11.0-11.2上始终返回nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆