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