V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
WildCat
V2EX  ›  Swift

现在定义类的静态方法(或者说 tpye method 更精确),用 class 和 static 都不限制了,这两者有什么区别吗?

  •  
  •   WildCat · 2015-12-04 19:09:35 +08:00 · 2851 次点击
    这是一个创建于 3038 天前的主题,其中的信息可能已经有所发展或是发生改变。
    class SomeClass {
        static func sMethod() {
            print("sMethod")
        }
    
        class func cMethod() {
            print("cMethod")
        }
    }
    
    SomeClass.cMethod()
    
    SomeClass.sMethod()
    

    上述运行起来没有区别,官方文档里只有提到 class func xxx(),不知道有深层次区别吗?

    1 条回复    2015-12-04 23:45:13 +08:00
    dorentus
        1
    dorentus  
       2015-12-04 23:45:13 +08:00 via iPhone   ❤️ 1
    static 的不能被子类 override
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2880 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:48 · PVG 21:48 · LAX 06:48 · JFK 09:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.