Split the string based on space iOS swift || Split string and save in an array iOS swift

Solution:

We can easily split the string value based on space and save it into an array using the split function like below

 In swift:


        var namStr = "First Middle last"
        var nameArr = split(namStr) {$0 == " "}
        nameArr[0]//First
        nameArr[1]//Middle

        nameArr[2]//last



In swift 2:

        var namStr = "First Middle last"
        let nameArrVal = namStr.characters.split{$0 == " "}.map(String.init)

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift