Safe

Swift pairs increased type safety with type inference, restricts direct access to pointers, and automatically manages memory—making it easy to create secure, stable software.

  • func

    configureLabels(labels:

    UILabel[]) {

  • let

    labelTextColor =
    UIColor.greenColor()

  • for

    label
    in
    labels {

  • //
    label inferred to be UILabel
  • label.textColor
    =
    labelTextColor
  • }
  • }

Modern

Swift includes optionals, generics, tuples, and other modern language features. Inspired by and improving upon Objective-C, Swift code feels natural to read and write.

  • 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")
  • }

Powerful

Take advantage of powerful pattern matching in Swift to write simple, expressive code. Format strings naturally with string interpolation. Use frameworks like Foundation and UIKit directly from Swift.

  • 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)")
  • }

Interactive

Use playgrounds to experiment with new technologies, analyze problems, and prototype user interfaces.

Fast

The Swift compiler applies advanced code analysis to tune your code for performance, letting you focus on writing great apps instead of on implementing complex optimizations.

IOS开发-Swift新语言初见的更多相关文章

  1. iOS开发Swift篇—(二)变量和常量

    iOS开发Swift篇—(二)变量和常量 一.语言的性能 (1)根据WWDC的展示 在进行复杂对象排序时Objective-C的性能是Python的2.8倍,Swift的性能是Python的3.9倍 ...

  2. 李洪强iOS开发Swift篇—02_变量和常量

    李洪强iOS开发Swift篇—02_变量和常量 一.语言的性能 (1)根据WWDC的展示 在进行复杂对象排序时Objective-C的性能是Python的2.8倍,Swift的性能是Python的3. ...

  3. iOS开发系列--C语言之基础知识

    概览 当前移动开发的趋势已经势不可挡,这个系列希望浅谈一下个人对IOS开发的一些见解,这个IOS系列计划从几个角度去说IOS开发: C语言 OC基础 IOS开发(iphone/ipad) Swift ...

  4. iOS开发Swift篇—(一)简单介绍

    iOS开发Swift篇—简单介绍 一.简介 Swift是苹果于2014年WWDC(苹果开发者大会)发布的全新编程语言 Swift在天朝译为“雨燕”,是它的LOGO 是一只燕子,跟Objective-C ...

  5. iOS开发Swift篇—(三)字符串和数据类型

    iOS开发Swift篇—(三)字符串和数据类型 一.字符串 字符串是String类型的数据,用双引号""包住文字内容  let website = "http://www ...

  6. iOS开发Swift篇—(四)运算符

    iOS开发Swift篇—(四)运算符 一.运算符 1.Swift所支持的部分运算符有以下一些 赋值运算符:= 复合赋值运算符:+=.-= 算术运算符:+.-.*./ 求余运算符:% 自增.自减运算符: ...

  7. iOS开发Swift篇—(六)流程控制

    iOS开发Swift篇—(六)流程控制 一.swift中的流程控制 Swift支持的流程结构如下: 循环结构:for.for-in.while.do-while 选择结构:if.switch 注意:这 ...

  8. iOS开发Swift篇—(九)属性

    iOS开发Swift篇—(九)属性 一.类的定义 Swift与Objective-C定义类的区别 Objective-C:一般需要2个文件,1个.h声明文件和1个.m实现文件 Swift:只需要1个. ...

  9. iOS开发Swift篇—简单介绍

    iOS开发Swift篇—简单介绍 一.简介 Swift是苹果于2014年WWDC(苹果开发者大会)发布的全新编程语言 Swift在天朝译为“雨燕”,是它的LOGO 是一只燕子,跟Objective-C ...

随机推荐

  1. dispatch_once认识分析

    dispatch_once为了确保代码运行一次 +(NSDateFormatter*)getDBDateFormat { static NSDateFormatter* format; static ...

  2. javascript于&quot;return obj === void 0&quot;这样的书面理由和优势

    得知underscore.js什么时候,查看源代码经常出现的类别似下面的代码: if (context === void 0) return func; if (array == null) retu ...

  3. hdu 3076 ssworld VS DDD (概率dp)

    ///题意: /// A,B掷骰子,对于每一次点数大者胜,平为和,A先胜了m次A赢,B先胜了n次B赢. ///p1表示a赢,p2表示b赢,p=1-p1-p2表示平局 ///a赢得概率 比一次p1 两次 ...

  4. Java线

    线程是一个单一的程序流程.多线程是指一个程序,可以在同一时间执行多个任务.每个任务是由一个单独的线程以完成.那.够同一时候在一个程序中执行,而且每个线程完毕不同的任务.程序能够通过控制线程来控制程序的 ...

  5. Visual Studio Team Services使用教程--邀请团队成员

  6. 减少iPhone手机系统版本号

    要减少移动版本号,本号,或者到"威风"站点或其他能够下载到iPhone固件的站点上下载固件,然后打开iTunes,进入到 然后按着(alt),同一时候用鼠标点击(更新button) ...

  7. 深入理解Linux修改hostname(转)

    当我觉得对Linux系统下修改hostname已经非常熟悉的时候,今天碰到了几个个问题,这几个问题给我好好上了一课,很多知识点,当你觉得你已经掌握的时候,其实你了解的还只是皮毛.技术活,切勿浅尝则止! ...

  8. linux sdio card睡眠治疗 sdio card removed解决方案

    近期调试几款sdio card suspend时都会出现sdio card removed,之后 要么死机要么模块不能正常工作.根本原因也就是休眠没有处理好.昨天最终找到了 解决方法. 1:host端 ...

  9. 创建Windows类别

    Windows在表单.控制.对话框基本上形成.Windows类是Windows形式的类型,可处理叙述性说明. 在Windows提前有很多定义Windows类别,但它可以很容易地创建自己的Windows ...

  10. Oracle 多行转多列

    Oracle 多行转多列,列值转为列名   前段时间做调查问卷,客户创建自定义问卷内容,包括题目和选项内容; 之后需要到处问卷明细,,,,麻烦来咯 于是到网上到处搜索,没有直接结果;于是又找各种相似的 ...