I have a Realm database called NewsCount . I need to download new news only if there is new news (accordingly, when newsCount changes). And I make a comparison when parsing data. But I can't properly compare them. How to compare them?
Here is the code.
private func parseJSONData(_ data: Data) { do { let temp: NSString = NSString(data: data, encoding: String.Encoding.utf8.rawValue)! let myNSData = temp.data(using: String.Encoding.utf8.rawValue)! guard let jsonResult = try JSONSerialization.jsonObject(with: myNSData, options: JSONSerialization.ReadingOptions.mutableContainers) as? NSDictionary else { return } guard let jsonNews = jsonResult["categories"] as? [AnyObject] else { print("Empty array") return } let realm = try Realm() let category = realm.objects(NewsCount.self) var array = [Int]() for i in category { array.append(i.newsCount) } print(array) print("News COUNT2 \(category)") for jsonnewes in jsonNews { let newsJson = NewsCount() //ВОТ ЗДЕСЬ Я ДОЛЖЕН СРАВНИТЬ if !UserDefaults.standard.bool(forKey: "AppStarted") || jsonnewes["count"] as! Int > array[jsonnewes as! Int]{ newsJson.newsID = jsonnewes["term_id"] as! Int newsJson.newsCount = jsonnewes["count"] as! Int //print("News COUNT2 \(newsJson.newsCount)") NotificationCenter.default.post(name: NSNotification.Name(rawValue: "downloadNew"), object: nil) } else { newsJson.newsID = jsonnewes["term_id"] as! Int newsJson.newsCount = jsonnewes["count"] as! Int //print("News COUNT3 \(newsJson.newsCount)") } insertOrUpdate(newsJson) } } catch { print(error) } } 