码迷,mamicode.com
首页 > 其他好文 > 详细

Swift基础数据类型和循环

时间:2014-08-05 13:37:19      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:http   io   数据   for   art   ar   cti   html   

本文是一篇swift的基础教材,讲解了swift语言的变量,数据类型和循环.准备学swift的同学可以参考学习下.

1 常量变量

    var myVariable = 42 //变量  
    myVariable = 50  
    let myConstant = 42 //常量  


2 显示指明变量类型


    let explicitDouble: Double = 70  


3 数组和字典


    var shoppingList = ["catfish", "water", "tulips", "blue paint"]   
    shoppingList[1] = "bottle of water"   
        
    var occupations = [   
        "Malcolm": "Captain", //前面是key 后面是value  
        "Kaylee": "Mechanic",   
    ]   
    occupations["Jayne"] = "Public Relations"  


4 创建初始化数组和字典


    let emptyArray = String[]()   
    let emptyDictionary = Dictionary<String, Float>()   

5数组添加


    var emptyarry = String[]()  
    emptyarry.append("dfd")  

6 for循环


    let sss = [11,12,43,554,12,434]  
    for i in 0..4 {  
         print("(i) = (sss[i])");  
             print("n");  
          }  
    for i in sss{  
          print(i);  
             print("n");  
          }  


7 switch

    let vegetable = "red pepper"   
    switch vegetable {   
    case "celery":   
        let vegetableComment = "Add some raisins and make ants on a log."   
    case "cucumber", "watercress":   
        let vegetableComment = "That would make a good tea sandwich."   
    case let x where x.hasSuffix("pepper"):   
        let vegetableComment = "Is it a spicy (x)?" fallthrough   
    default:   
        let vegetableComment = "Everything tastes good in soup."   
    }  

自:http://www.phperz.com/article/14/0802/15200.html

Swift基础数据类型和循环,布布扣,bubuko.com

Swift基础数据类型和循环

标签:http   io   数据   for   art   ar   cti   html   

原文地址:http://www.cnblogs.com/asdfaa/p/3891801.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!