Swift数组遍历

ArrayMap 笔记整理

https://blog.csdn.net/OneDeveloper/article/details/89817457

Swift数组遍历

https://www.jianshu.com/p/b6677deee72e

letcountryArray = ["中国","美国","俄罗斯","新加坡","英国"]

        /***数组的遍历***/

        //1:for in

        for index in 0..<4

        {

            let item = countryArray[index]

            print("遍历数组1:\(item)")

        }

        for item in countryArray

        {

            print("遍历数组2:\(item)")

        }

        //2:for in enumerated

        for(index, item)incountryArray.enumerated()

        {

            print("索引:\(index)  元素:\(item)")

        }

        //3:forEach

        countryArray.forEach{ (item)in

            print(item)

        }

        //4:stride to(不包含)

        forindexinstride(from:1, to:4, by:1) {

            print(index)

        }

        //5:stride through(包含)

        forindexinstride(from:0, through:4, by:2)

        {

            print(index)

        }

发布了15 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/sundaysme/article/details/100778703
今日推荐