zoukankan      html  css  js  c++  java
  • Swift

    1,结构体struct和枚举enum的静态属性,静态方法使用static关键字

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    struct Account
        var amount : Double = 0.0                 //账户金额 
        var owner : String = ""                   //账户名 
     
        static var interestRate : Double = 0.668  //利率
     
        static func interestBy(amount : Double) -> Double {
            return interestRate * amount 
        }
    }

    2,类class的类型属性,类型方法使用class关键字

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    class Account {
        var amount : Double = 0.0               // 账户金额 
        var owner : String = ""                 // 账户名 
      
        class var staticProp : Double {
            return 0.668 
        
     
        class func interestBy(amount : Double) -> Double {
            return 0.8886 * amount 
        }
       
    //访问静态属性 
    println(Account.staticProp)
  • 相关阅读:
    python:递归函数(汉诺塔)
    python:代码复用与函数递归
    unity接入平台sdk
    原型和原型链
    闭包js
    微信小游戏的排行榜重点
    微信简单的排行榜
    代理服务器出现问题解决方案
    nodejs的fs模块
    nodejs的l分数
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/4838100.html
Copyright © 2011-2022 走看看