import FoundationPRint("Hello, World!")var a = 5var b = 10let c = a+bprint(c,terminator:" ")var s = "hello xjc"s = "/(s) /(100)"print(s)var arr = ["hello":"xjc","he":"world"]print(arr["hello"])var arr1 = [String]()for index in 0...100{ arr1.append("Item /(index)")}//for value in arr1{//print(value)//}//var i = 0//while i<arr1.count{// print(arr1[i])// i+=1//}func sayHello(name:String){ print("Hello /(name)")}func getNums()->(Int,Int){ return(2,3)}sayHello(name:"xjc")let(a1,a2) = getNums()print(a1)print(a2)class Person{ var _name:String = "" init(name:String){ _name = name; print("hi /(_name)") // } func sayhel(){ print("hi /(_name)") }} var person = Person(name:"ws")//person._name = "ws"//print(person._name)person.sayhel()//继承class Student: Person{ override func sayhel() { super.sayhel() print("hihi") }}var s1 = Student(name:"xjc");//s1._name = "ws"s1.sayhel()//类功能的扩展extension Student{ func sayHa(){ print("haha") }}class ha:Student{ }var ha1 = ha(name:"1")ha1.sayhel()//使用接口protocol People{ func getName()->String}class Man:People{ func getName() -> String { return "xjc" }}var m1 = Man()print("name is /(m1.getName())")//命名空间class com{ class xjc{ }}extension com.xjc{ class Hi{ func sayHi(){ print("hi xjc") } }}extension com.xjc{ class Hello{ func sayHello(){ print("hello xjc") } }}var h = com.xjc.Hi()h.sayHi()var h1 = com.xjc.Hello()h1.sayHello()//定位错误class Math{ class func max(a:Int,b:Int)->Int{ NSLog("aaa") if a>b{ print("aaa") return a }else{ print("vbbb") return b } }}var maxNum = Math.max(a: 2,b: 5)print("/(maxNum)")//print("/(max(2,3))")var max_num = max(3,4)//print(max_num)
新闻热点
疑难解答