国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Swift基礎之方法實戰

2019-11-14 20:01:00
字體:
來源:轉載
供稿:網友

1.和之前一樣

2.代碼

  1 //  2 //  ViewController.swift  3 //  SwitfLesson_exam  4 //  5 //  Created by 薛雨侖 on 14-10-7.  6 //  Copyright (c) 2014年 Dylan. All rights reserved.  7 //  8   9 import UIKit 10  11 class ViewController: UIViewController { 12  13     override func viewDidLoad() { 14         super.viewDidLoad() 15          16         // 1. 17         // Change Two temper 18         // 2種元組的初始化 19         var a = "Alice" 20         var b = "Dylan" 21         var myType = (a, b) 22          23         var name:String 24         var family:String 25         (name, family) = ("Alice", "Dylan") 26          27         // test func change 28         swap(&a, with: &b) 29         PRintln(a) 30         println(b) 31          32         // 2. 33         // print String 34         // test func flexString 35         println(flexStrings(s1:"Alice ", s2: "Dylan")) 36          37         // 3. 38         // sumAny 39         // test func sumAny 40         println(sumAny(1, 2, 3)) 41          42         // 4. 43         // countFrom 44         // test func countFrom 45         countFrom(from: 1, to: 5) 46     } 47      48     /** 49     1. fun change 50     交換2個任意對象的值 51     */ 52     func swap<T>(inout a:T, inout with b:T) { 53         (a, b) = (b, a) 54     } 55      56     /** 57     2. func flexStrings 58     輸出字符串 59     */ 60     func flexStrings(s1:String = "", s2:String = "") ->String { 61         return s1 + s2 == "" ? "none" : s1+s2 62     } 63      64     /** 65     3. func sumAny 66     */ 67     func sumAny(anys: Any...) ->String { 68         return String( 69             (anys.map({item in 70                 switch item { 71                 case "" as String, 0 as Int: 72                     return -10 73                 case let s as String where s.toInt() > 0: 74                     return s.toInt()! 75                 case is Int: 76                     return item as Int 77                 default: 78                     return 0 79                 } 80             }) as [Int]).reduce(0, combine: { 81                 $0 + $1 82             }) 83         ) 84     } 85      86     /** 87     4. func countFrom 88     */ 89     func countFrom(#from: Int, to:Int) { 90         println(from) 91         if from < to { 92             countFrom(from: from + 1, to: to) 93         } 94     } 95  96     override func didReceiveMemoryWarning() { 97         super.didReceiveMemoryWarning() 98         // Dispose of any resources that can be recreated. 99     }100 101 102 }

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 栖霞市| 永嘉县| 延川县| 舞钢市| 巴彦县| 深州市| 花莲市| 东莞市| 桃园县| 浦东新区| 房山区| 宣城市| 紫金县| 滦平县| 棋牌| 黄石市| 彰化县| 岳阳市| 治多县| 积石山| 射阳县| 温泉县| 毕节市| 益阳市| 高雄县| 即墨市| 嘉黎县| 宝丰县| 梓潼县| 浑源县| 南昌市| 额敏县| 韩城市| 永靖县| 嘉峪关市| 三原县| 海兴县| 将乐县| 自贡市| 屯留县| 永春县|