WildCat
V2EX  ›  Swift

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

  •  
  •   WildCat · Dec 4, 2015 · 3450 views
    This topic created in 3854 days ago, the information mentioned may be changed or developed.
    class SomeClass {
        static func sMethod() {
            print("sMethod")
        }
    
        class func cMethod() {
            print("cMethod")
        }
    }
    
    SomeClass.cMethod()
    
    SomeClass.sMethod()
    

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

    1 replies    2015-12-04 23:45:13 +08:00
    dorentus
        1
    dorentus  
       Dec 4, 2015 via iPhone   ❤️ 1
    static 的不能被子类 override
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3223 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 12:30 · PVG 20:30 · LAX 05:30 · JFK 08:30
    ♥ Do have faith in what you're doing.