PRADIP KUMAR PRADIP KUMAR - 4 months ago 17x
Swift Question

How to accept Rating value of RateController as string in swift

I am fetching rating data from API as Array of String. But "ratingcontrol.rating" value only accept the Int value . so while population the rating in custom tableview cell It gives error. HOW TO RESOLVE IT?

Rating Declaration:

var Ratings:Array< String > = Array < String >()

Now I am fetching data from Api as:

var json: NSArray!
do {
json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions()) as? NSArray
} catch {

self.Ratings = json.valueForKey("rate") as! Array<String>

It successfully show me the value from Api. Now I am populating it into the customtableviewcell.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell =
forIndexPath: indexPath) as! ReviewCustomCell

**cell.ratingControl.rating = Ratings[indexPath.row]**
return cell

The above bold one shows error as "Cant accept value of type string to int".
Anyone give some idea to resolve it.


Lets try to take the rating value as array of integer instead array of string.

 // var Ratings:Array< String > = Array < String >()
   var Ratings:Array<Int > = Array<Int >()

Check if it works or not