//
// ViewController.swift
// swiftTest
//
// Created by wupeng on 15/11/23.
// Copyright © 2015年 wupeng. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let p = Person(name:"wup",numberOfLines:999999)
let pSimpleDesc = p.simpleDesc();
print(pSimpleDesc)
let p2 = Person(name: "nash", numberOfLines: 10000000)
print(p2.parrams)
p2.parrams = "nash131313131"
print(p2.parrams)
let mathfunc = self.getMathFunc("squre")
print(mathfunc(5))
print(self.squre(3))
print(self.cube(100))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// func sequre(num:Int) -> Int {
// return num * num
// }
// func cube(num:Int) -> Int {
// return num * num * num
// }
// func getMathFunc(type:String ) -> (Int) ->(Int) {
// switch (type) {
// case "sequre":
// return self.sequre
// default:
// return self.cube
// }
// }
func getMathFunc(type:String) -> (Int) ->Int {
switch type{
case "squre":
return { (num:Int) -> Int in return num * num }
default:
return {(num:Int) -> Int in return num * num * num }
}
}
var squre:(Int) -> Int = {(num:Int) -> Int in return num * num }
var cube :(Int) -> Int = {
return $0 * $0 * $0
}
// func getMathFunc(type:String) -> (Int) ->Int {
// func squre(num: Int) -> Int {
// return num * num
// }
// func cube(num :Int) -> Int {
// return num * num * num
// }
// switch type {
// case "squre":
// return squre
// default:
// return cube
// }
// }
func testFunc(name:String , day:String) ->String {
return "first arg :\(name) and SeconeString :\(day)"
}
func sumOf(name:String,numbers:Int...) -> Int {
var sum = 0
for number in numbers {
sum += number
}
print(name)
return sum
}
internal func test() {
let apples = 3;
let orange = 5;
let appleSumm = "i have \(apples + orange) apples"
print(appleSumm)
var shoppingList = ["fish","dog","cat"]
shoppingList[1] = "preson"
print(shoppingList)
var occupations = ["MalColm":"Person",
"kaylee":"Cat",]
print(occupations["MalColm"])
// let emptyArray = String[]()
let emptyDictionary = Dictionary<String,Float>()
// print(emptyArray)
print(emptyDictionary)
let scores = [76,393,3939,39392,2323,1100,8383]
for score in scores {
print(score);
}
var optionalString:String? = "Hi"
optionalString = nil
if optionalString != nil {
print(optionalString)
}
let vagetable = "Red Paper"
switch vagetable {
case "apple":
print("apple")
case "custome","Oh No":
print("two")
case let x where x.hasSuffix("Paper"):
print("\(x)")
default:
print("default")
}
var m = 2
repeat {
m = m*2
print(m)
} while m < 100
var n = 1024
while n > 0 {
n = n/2
print(n)
}
}
}
转载于:https://my.oschina.net/wupengnash/blog/534235