您的位置:首页 > 移动开发 > Swift

swift学习_xcode基础学习

2014-06-27 16:46 323 查看
android L已经在开发大会上公布了, 技术得跟上时代的潮流, 一心想在移动互联网中发展,只好努力学习 html+ js , oc ! 服务器运维我就不写了,就算是自己的生活记录。android 说真心话, 一直想写,结果发现自己很喜欢写得连续点,就像仙剑一样, 应该是能让人回味的那种,文笔不好 , 就先这些基础开始练习吧。

发呆中。。。。。

上一个教程中 xcode6 安装后,打开xcode开始界面,我突然发现 get start playground , 一直在犹豫他是神马。。。。

点击get start playground 之后,界面有大惊喜,这个是html 常会出现的实时页面, 记得用blog写md 语法的时候 ,就是这样的页面。。。。



好吧, var js的节奏啊 !! 瞬间激动了, 难道oc和js 合体了, swift果然是神器



接下来部分代码

// Playground - noun: a place where people can play

import Cocoa

var str = "Hello, playground" //变量
var x = 0.0, y = 0.0, z = 0.0
let numInt = 10 //常量
/**
*多行注释
*/
println(str) //输出函数
println(numInt)
println("str is \(str) num is \(numInt)")

/**
*需要注意Double
*/
let anotherPi = 3 + 0.14159
// anotherPi 会被推测为 Double 类型
let decimalInteger = 17
let binaryInteger = 0b10001       // 二进制的17
let octalInteger = 0o21           // 八进制的17
let hexadecimalInteger = 0x11     // 十六进制的17 很喜欢0x ,让我想起了做游戏外挂时的痛苦,读取内存基址

/**
* 元组 java中map的马甲,先这么理解吧
*/
let http404Error = (404, "Not Found")
let (statusCode, statusMessage) = http404Error
println("The status code is \(statusCode)")
// 输出 "The status code is 404"
println("The status message is \(statusMessage)")
// 输出 "The status message is Not Found"

let (justTheStatusCode, _) = http404Error
println("The status code is \(justTheStatusCode)")
// 输出 "The status code is 404"  只需要一部分元组值,分解的时候可以把要忽略的部分用下划线(_)标记

println("The status code is \(http404Error.0)")
// 输出 "The status code is 404" 下标方式取值
println("The status message is \(http404Error.1)")
// 输出 "The status message is Not Found" 下标方式取值
let http200Status = (statusCode: 200, description: "OK") //凌乱了, 居然可以这样写, 这是map<String , Object> 先这么理解吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: