swift学习
// // main.swift // mySwift // Created by鹏何on 15/7/7. // Copyright (c) 2015年鹏何. All rights reserved. // importFoundation varhello ="Hello,World!"//变量是定义 var s:Int=5;var mystring ="(hello)(s)"字符串连接 testvar = ["test","test2"5] vartestdic = ["test":"1","test2":3] testdic["test3"] =4 //循环 foruindexin0...100{ //判断 ifuindex %2==0{ testvar.append("item(uindex)") testdic[("test)")] = uindex }
} forvarvalueintestvar{ 遍历数组 // println(varvalue) } for(key,value)testdic{遍历字典 println((key) =(value)") } funcsyhell( name:String){ println( name ) } //必须先定义 syhell("test") //函数也是变量可以把函数当成变量来执行 vartestfun =syhell testfun"test2" //可以返回多个值 funcgetnumber() -> (Int,String) { return(2,27)">"test") } //接收返回值的类型 let(a,b) =getnumber() println(a) //定义类 classtest1 { var_name:String //构造函数 init(name:String){ _name= name; } funcsyshelltest1(){ "test:_name)"); } } varmytest1 =test1(name:"test1") mytest1.syshelltest1( ) //继承 classtest2 :test1{ //方法重写 overridefuncsyshelltest1() { varmytest2 =test2(name:"test2") mytest2() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |