What is the difference between static func and class func in Swift?

What is the difference between static func and class func in Swift?,第1张

概述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 stat

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

总结

以上是内存溢出为你收集整理的What is the difference between static func and class func in Swift?全部内容,希望文章能够帮你解决What is the difference between static func and class func in Swift?所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1023433.html

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

发表评论

登录后才能评论

评论列表(0条)

保存