Swift:Enum’无法构造,因为它没有可访问的初始值设定项’

Swift:Enum’无法构造,因为它没有可访问的初始值设定项’,第1张

概述我在 swift中得到了这个错误 ‘BlockColor’ cannot be constructed because it has no accessible initializers import Foundationimport SpriteKitlet NumberOfColors: UInt32 = 6enum BlockColor: Int, Printable {cas 我在 swift中得到了这个错误

‘Blockcolor’ cannot be constructed because it has no accessible
initializers

import Foundationimport SpriteKitlet NumberOfcolors: UInt32 = 6enum Blockcolor: Int,Printable {case Blue = 0,Orange,Purple,Red,teal,Yellowvar spritename: String {    switch self {    case .Blue:        return "blue"    case .Orange:        return "orange"    case .Purple:        return "purple"    case .Red:        return "red"    case .teal:        return "teal"    case .Yellow:        return "yellow"        }}var description: String {    return self.spritename}static func random() -> Blockcolor {    return Blockcolor(rawValue:Int(arc4random_uniform(NumberOfcolors)))!}}

我在这一行得到了一个错误

return Blockcolor(rawValue:Int(arc4random_uniform(NumberOfcolors)))!

我已多次查看我的代码,但我找不到错误的位置

我得到了同样的错误.我的错误是我没有提到枚举方法的任何返回(Int)类型(枚举Blockcolor:Int).初始化Int返回类型后.它的作品现在. 总结

以上是内存溢出为你收集整理的Swift:Enum’无法构造,因为它没有可访问的初始值设定项’全部内容,希望文章能够帮你解决Swift:Enum’无法构造,因为它没有可访问的初始值设定项’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1041687.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存