字典元組和指紋解鎖代碼

字典

//定義:
var dict = ["abacus" : "算盤","abnormal" : "異常","hello" : "你好"]
//print(dict["abnormal"])//可空類型
//print(dict["abnormal"]!)//string 類型
//
//dict["shit"] = "狗屎"
//print(dict["shit"]!)
//print(dict)
//
////修改元素
//dict["shit"] =  "牛糞"
//
////刪除元素
////第一種寫法
//dict.removeValueForKey("hello")
////第二種寫法
////dict["hello"] = nil
//print(dict)
//
////遍歷字典
//
////遍歷字典中的所有值
//for value in dict.values{
//    print(value)
//}
//
//for key in dict.keys{
//    print("\(key)-->\(dict[key])")
//}
//
////通過元組獲取字典的鍵值
//for (key ,value) in dict {
//    print("\(key)--> \(value)")
//}
//
//
////  哈希碼(hash code)/散列碼
////  MD5 / SHA-1//最經(jīng)典的2個(gè)hash算法
////創(chuàng)建集合:可以去除重復(fù)元素
//var a: Set<Int> = [1,2,3,1,2,5]
//print(a)
//
//a.insert(100)
//a.remove(2)
////集合的交集,差集,并集
//var b: Set<Int> = [3,5,7,9,11]
//
//print(a.intersect(b))   //交集
//print(a.union(b))       //并集
//print(a.subtract(b))    //差集 a里面有b里面沒有的
////判斷是不是它的子集
//print(b.isStrictSubsetOf(a))
//
//
////集合的遍歷
//for x in a {
//    print(x,terminator:" ")
//}

////創(chuàng)建數(shù)組
//let b = [1,2,3,1,2,5]
//print(b)


日期,系統(tǒng)時(shí)間代碼

et date = NSDate()//可以取到現(xiàn)在的系統(tǒng)時(shí)間
//    let cal = NSCalendar.currentCalendar()//拿到現(xiàn)在的日歷
//    let hour = cal.component(.Hour, fromDate: date)

指紋解鎖代碼,新概念閉包的第一次應(yīng)用

 override func viewDidLoad() {
        super.viewDidLoad()
        let errpoint = NSErrorPointer()
        let ctx = LAContext()
        //evalutepolicy方法的第三個(gè)參數(shù)是一個(gè)函數(shù)
//        該函數(shù)有兩個(gè)參數(shù)沒有返回值
//        給改參數(shù)傳參時(shí)可以在花括中寫一個(gè)匿名函數(shù)傳進(jìn)去
//        該匿名函數(shù)通常也稱之為閉包(closure)
        if ctx.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: errpoint) {
            ctx.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "請輸入指紋進(jìn)行支付", reply:
                { (isOk, err) -> Void in
                    if isOk {
                        print("支付成功")
                    }
                    else {
                        print("指紋驗(yàn)證失敗!請輸入密碼")
                    }
            })
        }
        else    {
            print("設(shè)備不支持指紋識別")
        }
        
        
    }

函數(shù)的幾種寫法

//函數(shù)的參數(shù)名
//函數(shù)名(外表參數(shù)名 內(nèi)部參數(shù)名: 類型,外部參數(shù)名 內(nèi)部參數(shù)名: 類型)
//可以使用_來作為外部參數(shù)名表示省略外部參數(shù)名
//func myMin(a x:Int, y:Int) -> Int {
//    return x < y ? x : y
//}
////函數(shù)調(diào)用時(shí)要寫函數(shù)的外部參數(shù)名
//print(myMin(a: 3,y:  5))



//  定義函數(shù)
//  func 函數(shù)名(參數(shù)列表) ->  返回類型{函數(shù)的執(zhí)行體}
//  調(diào)用swift函數(shù)時(shí),在默認(rèn)情況下從第二個(gè)參數(shù)開始需要寫函數(shù)名
//  如果調(diào)用函數(shù)的時(shí)候沒有給該函數(shù)參數(shù)可以給它賦個(gè)默認(rèn)值
//func sayHello(personName: String,alreadyGreeted: Bool = false) -> String {
//    if alreadyGreeted {
//        return "怎么又是你," + personName + "!"
//    }
//    else {
//        return "你好," + personName + "!"
//    }
//
//}
//
////  調(diào)用函數(shù)
////  函數(shù)名(參數(shù)值)
//print(sayHello("王大錘"))
//let str = sayHello("王大錘",alreadyGreeted: true)
//print(str)



//函數(shù)的可變參數(shù)列表(參數(shù)的個(gè)數(shù)是任意多個(gè))
//func  sum(nums: Int...) ->Int {
//    var total = 0
//    for num in nums {
//        total += num
//    }
//    return total
//}
//
//print(sum())
//print(sum(999))
//print(sum(1,2,3))
//

//可以使用元組(tuple)讓函數(shù)一次返回多條數(shù)據(jù)
//func minMax(array: [Int]) -> (min: Int, max: Int)? {
//    if array.isEmpty{
//        return nil
//    }
//    var currentMin = array[0]
//    var currentMax = array[0]
//    
//        
//        for value in array[1..<array.count] {
//            if value < currentMin {
//                currentMin = value
//            }
//            else if value > currentMax {
//                currentMax = value
//            }
//        }
//    
//    
//    return (currentMin, currentMax)
//}
//
//if let b = minMax([1,3,5,7,9,11,13,15,17]){ //處理可空類型的最好方法 若為空 函數(shù)就不會執(zhí)行
//    print(b.min)    //  print(b.0)
//    print(b.max)    //  print(b.1)
//}
//


//func swap(inout a: Int, inout _ b: Int) {
////    (a,b) = (b,a)
//    let temp = x
//    x = y
//    y = temp
//}
//
//var x = 5 ,y = 10
////函數(shù)調(diào)用的傳參都是傳值
//swap(&x,&y)
//print("x = \(x)")
//print("y = \(y)")



func swap(var x: Int, var _ y: Int) {
    
    (x,y) = (y,x)
}

var x = 5 ,y = 10
//函數(shù)調(diào)用的傳參都是傳值
swap(x,y)

print("x = \(x)")
print("y = \(y)")


//inout - 輸入輸出參數(shù)(不僅將數(shù)據(jù)傳入函數(shù)還要從函數(shù)中取出數(shù)據(jù))
//func createX(inout x: Int ) {
//    x = 1000
//}
//
//var x = 1
//createX(&x)
//print(x)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,781評論 25 709
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,071評論 4 61
  • 晚上接兒子回家在路上兒子就說我們回家看書吧!作業(yè)我都寫完了,我說兒子你最近寫作業(yè)挺快的,兒子說作業(yè)少我很快寫完了,...
    天宇嘛嘛閱讀 210評論 0 1
  • 姓名 學(xué)號 簡書鏈接 楊露露 05 20171123W7英語復(fù)盤日志 劉芳芳 12 20171123W7英語復(fù)盤...
    133宋雙芳閱讀 188評論 0 0

友情鏈接更多精彩內(nèi)容