Skip to content

Instantly share code, notes, and snippets.

@JaleelNazir
Last active July 27, 2017 06:27
Show Gist options
  • Save JaleelNazir/c5c98c1585ccdee33b6fbdbe5505bee1 to your computer and use it in GitHub Desktop.
Save JaleelNazir/c5c98c1585ccdee33b6fbdbe5505bee1 to your computer and use it in GitHub Desktop.
file.json to Object Mapper class using SwiftyJSON
if let path = Bundle.main.path(forResource: "FeedFile", ofType: "json") {
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .alwaysMapped)
let jsonData = JSON(data: data)
if jsonData != JSON.null {
if let arrOfFeed = Mapper<GlynkFeed>().mapArray(JSONObject: jsonData["feed"].arrayObject) {
if arrOfFeed.count > 0 {
if self.arrOfGlynkFeed == nil || self.refreshControl.isRefreshing {
self.arrOfGlynkFeed = arrOfFeed
} else {
self.arrOfGlynkFeed.append(contentsOf: arrOfFeed)
}
self.pageNo = self.pageNo + 1
} else {
if self.arrOfGlynkFeed == nil {
self.arrOfGlynkFeed = arrOfFeed
}
self.isLoaded = true
print("Get Near By Feed Empty, PAGE NO: \(self.pageNo)")
}
self.tableViewForFeed.reloadData()
}
} else {
print("Could not get json from file, make sure that file contains valid json.")
}
} catch let error {
print(error.localizedDescription)
}
} else {
print("Invalid filename/path.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment