博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Swift 语言概览 -自己在Xcode6 动手写1
阅读量:7289 次
发布时间:2019-06-30

本文共 1691 字,大约阅读时间需要 5 分钟。

Swift是什么?

Swift是苹果于WWDC 2014发布的编程语言,这里引用的原话:

Swift is a new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility.

Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible and more fun.

Swift’s clean slate, backed by the mature and much-loved Cocoa and Cocoa Touch frameworks, is an opportunity to imagine how software development works.

Swift is the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language.

简单的说:

  1. Swift用来写iOS和OS X程序。(估计也不会支持其它屌丝系统)
  2. Swift吸取了C和Objective-C的优点,且更加强大易用。
  3. Swift可以使用现有的Cocoa和Cocoa Touch框架。
  4. Swift兼具编译语言的高性能(Performance)和脚本语言的交互性(Interactive)。

Swift语言概览

// Playground - noun: a place where people can playimport Cocoavar str = "Hello, playground"var str1 = "Hello Wrold!!!"var str2 = "O(∩_∩)O哈哈~"// Hello, worldprintln("Hello, world")// 变量与常量// Swift 使用 var 声明 变量 , let 声明常量var myVariable = 42myVariable = 50let myConstant = 42// 类型推导let explicitDouble : Double = 70// Swift 不支持隐式 类型转换 (所以需要显式类型转换)let label = "The width is"let width = 94let width1 = label + String(width)// 使用 \(item) 的形式进行 字符串格式化let apples = 3let orages = 5let sum = "I have \(apples) apples."let sum1 = "I have \(apples + orages) pieces of fruit."// 数组和字典// Swift 使用[] 操作符声明 数组(array)和字典 (dictionary)var listArr = ["fish","water","apple","rice"]listArr[1] = "bottle of water"var dict = [    "name": "melody",    "age" : "26",]dict["sex"] = "female"// 一般使用初始化器(initializer)语法创建空数组和空字典let emptyArray = String[]()let emptyDict = Dictionary
()

Xcode贴图

 

 

 

 

转载于:https://www.cnblogs.com/yaoji/p/3765789.html

你可能感兴趣的文章
python3csv与xlsx文件操作模块(csv、xlsxwriter)
查看>>
开启线程方式
查看>>
xdebug
查看>>
Css之 间距初始化
查看>>
lsnrctl启动报错,Linux Error: 29: Illegal seek
查看>>
IDEA github
查看>>
linux 驱动学习笔记05--文件系统与设备文件系统
查看>>
unresolved external symbol __forceAtlDllManifest错误的解决
查看>>
Linux的.run文件简单制作
查看>>
ubuntu解压命令(转)
查看>>
C#获取获取北京时间多种方法
查看>>
动态语言的灵活性是把双刃剑 -- 以 Python 语言为例
查看>>
1. 字节序的转换
查看>>
ubuntu14.04LTS下ECLIPSE+JAVA搭建
查看>>
学习RxJS: 导入
查看>>
PowerDesigner大小写转换
查看>>
纯 CSS 利用 label + input 实现选项卡
查看>>
Ubuntu 上安装R
查看>>
How .Net code can call unmanaged code?
查看>>
Archlinux安装配置以及遇到的问题
查看>>