I am trying to use Osmosis to fetch data from a website. I made a button that calls a function where I set the osmosis scope. My issue is that when I click on the button for the first time, the data is fetched from the site, but if I click again on the button, I still get the same data even tough the data has changed on the website. Here's a snippet of my code:
import UIKit
import Osmosis
class ViewController: UIViewController {
@IBOutlet weak var quote: UILabel!
var array: [[String: AnyObject]] = []
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.quote.text = "This is my initial text."
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func getQuotes() {
var updateText: String = ""
Osmosis(errorHandler: { (error) -> Void in
print(error)
})
.get(NSURL(string: "http://www.excemple.com")!)
.find(OsmosisSelector(selector: ".wrapper"), type: .CSS)
.populate([
OsmosisPopulateKey.Single("div") : OsmosisSelector(selector: ".div")
], type: .CSS)
.list { (dict) -> Void in
self.array.append(dict)
// Cast self.array[0] to String
updateText = self.array[0]["div"] as! String
// Truncate the string to remove unwanted \n \t
updateText.removeAtIndex(updateText.startIndex)
updateText.removeAtIndex(updateText.startIndex)
updateText.removeAtIndex(updateText.endIndex.predecessor())
print(updateText)
//Update UI by the main thread (to avoid slow display update)
dispatch_async(dispatch_get_main_queue()) {
self.quote.text = updateText
}
}
.start()
}
@IBAction func refreshButton(sender: AnyObject) {
getQuotes()
}
Hi,
I am trying to use Osmosis to fetch data from a website. I made a button that calls a function where I set the osmosis scope. My issue is that when I click on the button for the first time, the data is fetched from the site, but if I click again on the button, I still get the same data even tough the data has changed on the website. Here's a snippet of my code:
How can I refresh my data fetch by Osmosis ?