In this project I am trying to display a section of a webpage (weather-forecast.com) in my app. I've downloaded the html content into 'webContent' and used componentsSeparatedByString to break up the html code into an array of Strings to then grab the index I desire for my app. This part is in 'websiteArray1' and this value is a string "Mostly dry. Very mild (max 17°C on Sat afternoon, min 8°C on Fri night). Winds increasing (calm on Fri night, fresh winds from the ESE by Sun night)." It contains ° instead of the symbol ° and I am trying to use the stringByReplacingOccurrencesOfString to replace ° with °. I'm getting an that this method can't be called on a string but only NSString so then I tried converting my string to an NSString but now I am getting the error " [String] is not convertible to NSString".
Can anyone point me in the right direction on how to convert to an array of NSString or an alternative way to use the stringByReplacingOccurrenceOfString method?
let url = NSURL(string: "http://www.weather-forecast.com/locations/London/forecasts/latest")!
let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) -> Void in
if let urlContent = data {
let webContent = NSString(data: urlContent, encoding: NSUTF8StringEncoding)
let websiteArray = webContent?.componentsSeparatedByString("3 Day Weather Forecast Summary:</b><span class=\"read-more-small\"><span class=\"read-more-content\"> <span class=\"phrase\">")
if websiteArray?.count > 0{
//print(websiteArray![1])
var weatherArrayWithDeg = websiteArray![1].componentsSeparatedByString("</span>")
// Need to convert to NSString to use stringByReplacingOccurenceOfString, want to separate '$deg;' for ' °'
let weatherArray = (weatherArrayWithDeg as NSString).stringByReplacingOccurrencesOfString("°", withString: " °")
print(weatherArrayWithDeg[0])
}
}
}
task.resume()