zoukankan      html  css  js  c++  java
  • swift的static和class修饰符---What is the difference between static func and class func in Swift?

    Special Kinds of Methods

    Methods associated with a type rather than an instance of a type must be marked with the static declaration modifier for enumerations and structures, or with either the static or class declaration modifier for classes. A class type method marked with the class declaration modifier can be overridden by a subclass implementation; a class type method marked with static can’t be overridden.

    Variable Declaration

    A variable declaration introduces a variable named value into your program and is declared using the var keyword.

    Variable declarations have several forms that declare different kinds of named, mutable values, including stored and computed variables and properties, stored variable and property observers, and static variable properties. 

    Type Variable Properties

    To declare a type variable property, mark the declaration with the static declaration modifier. Classes may mark type computed properties with the class declaration modifier instead to allow subclasses to override the superclass’s implementation. Type properties are discussed in Type Properties.

    In a class declaration, the static keyword has the same effect as marking the declaration with both the class and final declaration modifiers.

    Protocol Method Declaration

    To declare a class or static method requirement in a protocol declaration, mark the method declaration with the static declaration modifier. Classes that implement this method declare the method with the class modifier. Structures that implement it must declare the method with the static declaration modifier instead. If you’re implementing the method in an extension, use the class modifier if you’re extending a class and the static modifier if you’re extending a structure

    https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//apple_ref/doc/uid/TP40014097-CH34-ID483

  • 相关阅读:
    POJ 1811 Prime Test (Rabin-Miller强伪素数测试 和Pollard-rho 因数分解)
    POJ 1200 Crazy Search (哈希)
    POJ 1061 青蛙的约会 (扩展欧几里得算法)
    POJ 1035 Spell checker (模拟)
    hud 2554 N对数的排列问题 (规律)
    HDU 2522 A simple problem (模拟)
    Python环境配置及项目建立
    IDEA通过MyBatis generator生成数据库表的对象
    复制、粘贴、剪切 操作
    下载歌曲(以QQ音乐为例)
  • 原文地址:https://www.cnblogs.com/feng9exe/p/9856501.html
Copyright © 2011-2022 走看看