发布于 2014-07-29 12:25:44 | 178 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Swift教程,程序狗速度看过来!

Swift编程语言

SWIFT,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C*共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序。


本文介绍了苹果刚刚发布的Swift语言的几个主要特性,感兴趣的同学看一下.

 

 

        1         Safe

    • func configureLabels(labelsUILabel[]) {

    •    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 = (2040)

  • switch size {

  • case let (widthheightwhere width == height:

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

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

  •    println("small rectangle")

  • case let (widthheight):

  •    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<String, Float>()



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务