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())

  • 相关阅读:
    [Tips]git cannot lock ref
    [BUG]Git Sever搭建与相关错误处理
    [Tips]matplotlib 命令行画图保存
    [Tips]Torch功能点记录
    5G元年教育产业再出发 科技赋能的“风口与风险”仍待明晰
    Adobe逆天AI黑科技:美颜照克星,秒还原PS照片
    计算机算法能听声音绘制人脸
    2019 CESA,智能座舱越来越“懂你”
    谷歌首席决策科学家:AI难免犯错,唯有人类可以悬崖勒马
    百度:如何将AI进行到底?
  • 原文地址:https://www.cnblogs.com/ZGSmile/p/5692659.html
Copyright © 2011-2022 走看看