打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
iOS Swift学习 数组
学无止境啊,赶紧总结,最基本的知识===数组操作
       
//数组
 
        var shopList = ["apple","pear"]
        //获取下标元素
        myLabel.text = shopList[0]
        //数组增加元素
        shopList += ["peach","waterPalon"]
        println("1-1 the array is \(shopList) array count is \(shopList.count)")
        //数组末尾添加一个元素
        shopList.append("banana")
        println("1-2 the array is \(shopList)")
       
        //根据索引改变数组元素
        shopList[1] = "yellow"
        println("1-3 the array is \(shopList)")
       
        //替换指定范围的元素
        shopList[2...3] = ["red","blue","green","blue"]
        println("1-4 the array is \(shopList)")
        //插入到指定位置
        shopList.insert("meat", atIndex: 3)
        println("1-5 the array is \(shopList)")
        //移除
        shopList.removeLast()
        println("1-6 the array is \(shopList)")
        //移除某个下标的元素
        shopList.removeAtIndex(0)
        println("1-7 the array is \(shopList)")
        //打印对应元素
        for (index, value) in enumerate(shopList) {
            println("Item \(index + 1): \(value)")
        }
//==== 此行遍历的方法是xcode6中的方法,在xcode7中,使用
//打印对应元素
        for (index, value) in shopList.enumerate() {
            print("Item \(index + 1): \(value)")
        }
2016-05-04 修改
另:
println  用print 替代     




本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
8、WPS JS | 九九乘法表(Array.map()方法)
php二维数组
PHP如何使用array_unshift()在数组开头插入元素
一个实用的ASP字符串、数组输出函数
对GoLang里的slice要谨慎使用append操作
Java 实例 – 数组排序及元素查找 | 菜鸟教程
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服