An NSMutableArray is an NSArray is a subclass of NSArray.But,we can really
another immutable instance by the following way.In this post, I have shared some examples - how to turn a swift Array to Mutable Array or vice versa.This is my first article in swift for the beginners.Feel free to share your comments. |
|
1.How to convert NSMutableArray to Swift Array in swift?
Answer: var myMutableArray = NSMutableArray(array: ["xcode", "eclipse", "net bins"]) var myswiftArray = myMutableArray as NSArray as! [String] |
Answer:
We can convert the SwiftArray to a MutableArray by using the following code.
let myArray: NSArray = ["iOS","Android","PHP"]
var myMutableArray = NSMutableArray(array:myArray)
print(myMutableArray)
3.How to convert an array of characters into string in Swift without using any separator?
Answer:
let SwiftCharacterArray: [Character] = ["a", "b", "c", "d"]
let SwiftString = String(characterArray)
print(SwiftString)
4.How to convert an array of Strings into a string in Swift without using any separator?
Answer:
let SwiftStringArray = ["cocos2d", "cocos2d-x", "UIKit"]
let SwiftCharacterArray = SwiftStringArray.flatMap { String.CharacterView($0) }
let SwiftString = String(SwiftCharacterArray)
print(SwiftString)
5.How to convert an array of Strings into a string in Swift using space as separator?
Answer:
let SwiftStringsArray = ["Model", "View", "Controller"]
let MySwiftString = SwiftStringsArray.joinWithSeparator(" ")
print(MySwiftString)
6.How to convert an array of Strings into a string in Swift using separator?
Answer:
let SwiftStringsArray = ["iPhone", "iPad", "iPod"]
let MySwiftString = SwiftStringsArray.joinWithSeparator(",")
print(MySwiftString)
6.How to convert Swift String into an Array?
Answer:
let Ustring : String = "iOS Developer Questions"
let characters = Array(Ustring.characters)
print(characters)
Read:
An Introduction To The Swift Programming Language
Swift 2 Tutorial Part 2: Basics
How to Integrate Google Signin SDK in iOS Application using Swift
How To Add A SWIFT Bridging Header in iOS