zoukankan      html  css  js  c++  java
  • swift 定义枚举和结构体 及使用

     //定义枚举

            enum MapDirection {

                case North

                case South

                case East

                case West

                func simpleDescription() -> String {

                    switch self {

                    case .North:

                        return "North"

                    case .South:

                        return "South"

                    case .East:

                        return "East"

                    case .West:

                        return "West"

                    }

                }

            }

            

            // 使用枚举

            let en: MapDirection = MapDirection.North

            var en = MapDirection.North

            print(en.simpleDescription())

            en = .West

            print(en.simpleDescription())

            

            //定义结构体

            struct Summation {

                var addend: Int

                var augend: Int

                

                var addstring: String

                var augstring: String

                

                func sum() -> Int {

                    return addend + augend

                }

                

                func sumstring() -> String {

                    return addstring + augstring

                }

                

            }

            

            //创建一个结构体

    //        let newStruct = Summation(addend: 10, augend: 20)

            let newStruct = Summation(addend: 10, augend: 20, addstring: "newStruct", augstring: "newStruct")

            

            //使用结构体内的方法

            let sum = newStruct.sum()

            print(sum)

            

            print(newStruct.sumstring())

  • 相关阅读:
    wpf 文字动态动画效果
    c# 使用 Tchart控件之数据绑定
    Linq to sql学习之查询句法
    非常有用的查询所有SqlServer数据库字典的操作
    利用WPF建立自适应窗口大小布局的WinForm窗口
    SqlMethods
    wpf 炫彩动画效果简单实例
    SetBkMode与SetBkColor理解
    Windows的字体LOGFONT
    GetWindowRect和GetWindDC GetClientRect和GetDC 在标题栏输入文字
  • 原文地址:https://www.cnblogs.com/ZGSmile/p/5692659.html
Copyright © 2011-2022 走看看