ios – 使用未解析的标识符“静态”

ios – 使用未解析的标识符“静态”,第1张

概述我已经更新了 xcode 8.0 swift 3,我发现了很多错误.这是其中之一: Use of unresolved identifier ‘Static’ 这是我在以前的版本xcode 7.3.1 swift 2中创建和使用的类. import UIKitenum FONTSIZE:Int{ case sizesmall = 1 case sizesbig = 2 我已经更新了 xcode 8.0 swift 3,我发现了很多错误.这是其中之一:

Use of unresolved IDentifIEr ‘Static’

这是我在以前的版本xcode 7.3.1 swift 2中创建和使用的类.

import UIKitenum FontSIZE:Int{    case sizesmall = 1    case sizesbig = 2    case sizemedium = 3}class sizeFont: NSObject {    private static var __once: () = {            Static.instance = sizeFont()        }()    class func getSize(_ enumFont : FontSIZE) -> CGfloat {        var siz = 17        switch(enumFont){        case .sizesbig:            if((UserDefaults.standard.value(forKey: "Fontsize") as AnyObject).int32Value == 0){// kecil                if(isphone()){                    siz = 22//17                }else{                    siz = 22//24                }            }else if((UserDefaults.standard.value(forKey: "Fontsize") as AnyObject).int32Value == 1){// besar                if(isphone()){                    siz = 30//19                }else{                    siz = 30//28                }            }else{                if(isphone()){                    siz = 22//17                }else{                    siz = 22//22                }            }            break        case .sizesmall:            if((UserDefaults.standard.value(forKey: "Fontsize") as AnyObject).int32Value == 0){// kecil                if(isphone()){                    siz = 17//15//12                }else{                    siz = 24//22//19                }            }else if((UserDefaults.standard.value(forKey: "Fontsize") as AnyObject).int32Value == 1){// besar                if(isphone()){                    siz = 19//17//15                }else{                    siz = 28//26//24                }            }else{                if(isphone()){                    siz = 17//15//12                }else{                    siz = 24//22//19                }            }            break        case .sizemedium:            if((UserDefaults.standard.value(forKey: "Fontsize") as AnyObject).int32Value == 0){// kecil                if(isphone()){                    siz = 15                }else{                    siz = 22                }            }else if((UserDefaults.standard.value(forKey: "Fontsize") as AnyObject).int32Value == 1){// besar                if(isphone()){                    siz = 17                }else{                    siz = 26                }            }else{                if(isphone()){                    siz = 15                }else{                    siz = 22                }            }            break        }        return CGfloat(siz)    }    func getnaMetag(){    }    class func isphone() ->Bool {        if(UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone){            return true        }else{            return false        }    }    // example singleton swift    class var sharedInstance: sizeFont {        struct Static {            static var oncetoken: Int = 0            static var instance: sizeFont? = nil        }        _ = sizeFont.__once        return Static.instance!    }}

红线代码是Static.instance = sizeFont().

我不知道为什么我会得到这个,其他人都知道吗?

解决方法 静态在类变量中声明,导致var声明之外的每个人都不可达,只是将它移到外面.
...struct Static {    static var oncetoken: Int = 0    static var instance: sizeFont? = nil}// example singleton swiftclass var sharedInstance: sizeFont {    _ = sizeFont.__once    return Static.instance!}...
总结

以上是内存溢出为你收集整理的ios – 使用未解析标识符“静态”全部内容,希望文章能够帮你解决ios – 使用未解析的标识符“静态”所遇到的程序开发问题。

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

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

原文地址:https://54852.com/web/1115075.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存