Swift语言特性及基本数据类型

发布时间:2020-07-07 15:01:10 作者:510202
来源:网络 阅读:496

Today ,苹果刚刚发布了Swift语言,我们来看下Swift的几个主要特性:



        1         Safe

 

                  4            Interactive 

                  5              Fast。

-------------------------------------

基本数据类型:

 1 简单属性:

                  let:  恒定常量

                  var:可变常量

                        1.1 定义常量不用指定其固定类型,编译器会处理,如需更多识别,请添加前缀:

                        let implicitInteger = 70

                        let implicitDouble = 70.0

                        let explicitDouble: Double = 70

                        println("int:\(implicitInteger)  double:\(implicitDouble) explicitDoubledss:\(explicitDouble)");

2  类型之间的转化,必须是显示的:

                        let label = "width is :";

                        let width = 54;

                        let widthLabel = label + String(width)

                        println("LabelWidth:\(widthLabel)");

 3    使用反斜杠在String中插入内容,代码参考2 

 4   使用中括号创建数组和字典:

    

        var shoppingList = ["catfish", "water", "tulips", "blue paint"]

        shoppingList[1] = "bottle of water"

        var occupations = [

            "Malcolm": "Captain",

            "Kaylee": "Mechanic",

        ]

        occupations["Jayne"] = "Public Relations"

        println("array is \(shoppingList)")

        println("dictionary is :\(occupations)")

        //create Empty 

        let emptyArray = String[]()

        let emptyDictionary = Dictionary<String, Float>()


下一篇文章将介绍控制语句

推荐阅读:
  1. swift基本数据类型都有哪些
  2. Swift2.0(1)Swift简介

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

swift 数据类 wif

上一篇:使用linux的init命令切换系统运行级别

下一篇:python列表中能不能用中文

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》