-3

how to add an string variable values into an string array in swift ? After assigning whole values i want to populate these array elements into an UITableView.

[ArrayName abbObject:Stringname]; //objective-c code

swift code ?

this objective-c statement to be converted into swift. The value will change dynamically. At these time whole value to be inserted into array and it can be retrieved for further use -thank you

SARATH SASI
  • 1,395
  • 1
  • 15
  • 39
  • 1
    this objective-c code isn't correct. Also you have to show us your attempts – Christian Feb 09 '15 at 09:51
  • @ChristianWoerz woerz Excuse me, i didn't understand the wrong in that code. That code works fine in the case of Objective-C for me – SARATH SASI Feb 09 '15 at 10:26
  • It should be addObject – Christian Feb 09 '15 at 10:27
  • ok thanks for your information. Actually it just an spelling mistake. Even the compiler will show the error and auto correction suggestions. – SARATH SASI Feb 09 '15 at 10:37
  • 1
    think this is covered in "A Swift Tour" on one of the first few pages of the Swift book. Did you consult any basic introduction to Swift before posting this question? – Max MacLeod Feb 09 '15 at 10:52
  • @MaxMacLeod no actually i was in a hurry to get the solution. After some try i got the solution without any reference -thank you – SARATH SASI Feb 09 '15 at 10:56

2 Answers2

2

You can use the append function. Here's what you should do:

var a:[NSString]=[]
var for:NSString="for"
a.append(for)
Dhruv Ramani
  • 2,633
  • 2
  • 22
  • 29
1

You can add object to an array string using the following code

syntax: array_name.append.(var_name)

example:

    var peri: [NSString] = []
    var per : NSString = "\(peripheral.name)"
    peri.append(per)

In the above case "peri" is a string array, "per" is a string variable and append is keyword used to append the values into the array

SARATH SASI
  • 1,395
  • 1
  • 15
  • 39