Implementing the conversion and traversal of array array and Nsarray array in Swift

Source: Internet
Author: User

Array is the data type of the arrays in Swift. The Nsarray is the array data type in OC. There is a connection between the two. Some of the things in OC can sometimes be used in swift. Today we're going to use Nsarray and array in Swift, and convert.

(1) Declare an array of arrays. and to traverse. The code is as follows:

    Let stringarray:array<string> = ["Ten", "+", "+", "+", "+"] for        index in stringarray{                    println (Index)        }        

The output results are as follows:

Using Swift to traverse array arrays is no matter what the problem, you can use the for...in loop.


(2) Declare a Nsarray array and iterate through the code such as the following:

     Let Stringnsarray:nsarray = ["Ten", "+", "+", "Max", "[]"] for                index in stringnsarray{                    println (index)        }

The output results are as follows:

A visible Nsarray array can also be declared and traversed directly in Swift.


(3) Declare an array of Nsarray and convert to array. To iterate:

   Let Stringnsarray:nsarray = ["Ten", "+", "+", "Max", "[]] let        stringarray:[string] = Stringnsarray as! [String]                For index in stringarray{                    println (index)        }

The output results are as follows:


It is visible that Nsarray is able to assign values directly to array arrays after type conversion. It can then be traversed.


(4) Declare an array of arrays, convert to Nsarray, and then iterate:

     Let stringarray:array<string> = ["Ten", "+", "+", "Max", "[]"] let        Stringnsarray:nsarray = Stringarray for        Index in stringnsarray{                    println (index)        }

The output results are as follows:

The ability to see array arrays can also be converted directly to Nsarray. and to traverse.


In summary, the array of swift arrays is very well compatible with the Nsarray in OC. Ability to directly perform assignment conversions.


GitHub home: https://github.com/chenyufeng1991.

Welcome to visit us!














Implementing the conversion and traversal of array array and Nsarray array in Swift

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.