Swift语言特性及基本数据类型-创新互联

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

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:主机域名虚拟主机、营销软件、网站建设、融水网站维护、网站推广。

        1      Safe

    • func configureLabels(labels: UILabel[]) {

    •   let labelTextColor = UIColor.greenColor()

    •   for label in labels {

    •     // label inferred to be UILabel

    •     label.textColor = labelTextColor

    •   }

    • }

    • 2        Modern

    • let cities = ["London", "San Francisco", "Tokyo", "Barcelona", "Sydney"]

    • let sortedCities = sort(cities) { $0 < $1 }

    • if let indexOfLondon = find(sortedCities, "London") {

        println("London is city number \(indexOfLondon + 1) in the list")

      }

      3        Powerful:

  • let size = (20, 40)

  • switch size {

  • case let (width, height) where width == height:

  •   println("square with sides \(width)")

  • case (1..10, 1..10):

  •   println("small rectangle")

  • case let (width, height):

  •   println("rectangle with width \(width) and height \(height)")

  • }


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

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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前标题:Swift语言特性及基本数据类型-创新互联
转载源于:http://pwwzsj.com/article/ddeioj.html