hello programmers and engineers , basically I want to access and show every title item in json file into collection View (that have a cell contains an image view and label ). I mean every title and image should arrange in collectionView , thanks for attention, here is my json data :
{"end":1,"data":[{"userId":{"Id":"608e3f16adb3d241e83b7e91","name":"maryam","userName":"maryam","email":"mmmaryam#gmail.com","phone":"0921984512"},"isoGld":false,"image":["images/product/2021-05-02T09-40-55.719Z-images.jpg"],"check":false,"date":"2021-05-02T05:49:42.854Z","_id":"608e73a7adb3d241e83b7e97","title":"ytrfds","about":"\n music moein","country":"60895361d3dc582b43f1c4d9","city":"60895370d3dc582b43f1c4da","telePhone":"562866567897654897","countryText":"gtfrd","cityText":"lklk","category":"6067fe1df420e0042cb93209","address":"\n arabic","dateOfEx":"2021-05-09T00:00:00.000Z","dateOfStart":"2021-05-26T00:00:00.000Z","offer":"20","createdAt":"2021-05-02T09:40:55.744Z","updatedAt":"2021-05-02T09:40:55.744Z","__v":0},{"userId":{"Id":"608e3f16adb3d241e83b7e91","name":"maryam","userName":"maryam","email":"mmmaryam#gmail.com","phone":"0921984512"},"isoGld":false,"image":["images/product/2021-05-02T09-47-17.699Z-download (2).jpg"],"check":false,"date":"2021-05-02T05:49:42.854Z","_id":"608e7525adb3d241e83b7e99","title":"abbass fgaderi","about":"\n abass ghaderee","country":"60895361d3dc582b43f1c4d9","city":"60895370d3dc582b43f1c4da","telePhone":"444444444444444","countryText":"gtfrd","cityText":"gfdsxz","category":"6067fe1df420e0042cb93209","address":"\n karaj","dateOfEx":"2021-05-12T00:00:00.000Z","dateOfStart":"2021-05-30T00:00:00.000Z","offer":"25","createdAt":"2021-05-02T09:47:17.740Z","updatedAt":"2021-05-02T09:47:17.740Z","__v":0}]}
and also here is my code :
lass HomeViewController: UIViewController, UICollectionViewDataSource {
#IBOutlet weak var collectionView: UICollectionView!
let collectionOffer = OfferCollectionViewCell()
var txt : String = " "
var cid : String = " "
var numberOfItem : Int = 0
var titleArray : [String] = []
var imageArray : [String] = []
var offerImage : [UIImage] = []
override func viewDidLoad() {
super.viewDidLoad()
print("\n iiiiiiiiiid is \(cid)")
//HomeViewController.shared.fetchOffer()
fetchOffer()
collectionView.dataSource = self
// print("aksha hast : \(imageArray)")
}
struct welcomeJson: Codable { // this is where i have this error
let userId : UserID
let isoGld , check : Bool
let image : [String]
let v : Int
let date, id , title,countryid,about , cityid, telePhone, countryText,cityText, category, address, dateOfExpire , dateOfStart , offer , createdAt, updatedAt : String
enum CodingKeys : String , CodingKey {
case userId
case isoGld
case image
case check
case date
case id = "_id"
case title
case countryid = "country"
case cityid = "city"
case telePhone
case countryText
case cityText
case category
case address
case dateOfExpire = "dateOfEx"
case dateOfStart
case offer
case about
case createdAt
case updatedAt
case v = "__v"
}
}
struct UserID : Codable {
let ID, name, userName , email, phone : String
enum CodingKeys : String , CodingKey {
case ID = "Id"
case name
case userName
case email
case phone
}
}
struct Data1: Codable {
var data: [welcomeJson]
enum Codingkeys : CodingKey {
case data
}
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return numberOfItem
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cellol = collectionView.dequeueReusableCell(withReuseIdentifier: "OfferCollectionViewCell", for: indexPath) as! OfferCollectionViewCell
// cellol.offerImageView.image = UIImage(imageLiteralResourceName: imageArray[0])
cellol.offerImageView.image = UIImage(named: imageArray[0])
cellol.titleLabel.text = titleArray[0]
return cellol
}
func fetchOffer() {
if let url = URL(string: "http://5.63.13.16:8080/api/product/search/getByquerys?page=1&limit=10&city=\(cid)") {
print("url is : \(url)")
URLSession.shared.dataTask(with: url) {data,response,error in
if let data = data {
let jsondec = JSONDecoder()
do {
let parsedJS = try jsondec.decode(Data1.self, from: data)
for element in parsedJS.data {
self.numberOfItem = element.title.count
self.titleArray.append(element.title)
// self.imageArray.append(UIImage(element.image))
print("akse ma midoni ine : \(element.image)")
self.imageArray.append(element.image[0])
print("kole aksa ine : \(self.imageArray)")
//self.imageArray.append(contentsOf: element.image[0...])
// print("deghat kon : \(self.imageArray)")
}
}
catch {
print("error is : \(error) ")
}
DispatchQueue.main.async {
self.collectionView.reloadData()
}
}
}.resume()
}
and also here is my result with this code on simulator :
Your approach cannot work.
You assign the length of a string to numberOfItems which has nothing to do with the expected number.
Always return the number of items in the data source array dynamically in numberOfItems
Never split a struct into multiple arrays for the data source.
Use one data source array so replace
var numberOfItem : Int = 0
var titleArray : [String] = []
var imageArray : [String] = []
var offerImage : [UIImage] = []
with
var userData = [welcomeJson]() // please name structs with starting uppercase letter
In fetchOffer() replace
let jsondec = JSONDecoder()
do {
let parsedJS = try jsondec.decode(Data1.self, from: data)
for element in parsedJS.data {
self.numberOfItem = element.title.count
self.titleArray.append(element.title)
// self.imageArray.append(UIImage(element.image))
print("akse ma midoni ine : \(element.image)")
self.imageArray.append(element.image[0])
print("kole aksa ine : \(self.imageArray)")
//self.imageArray.append(contentsOf: element.image[0...])
// print("deghat kon : \(self.imageArray)")
}
}
with
let jsondec = JSONDecoder()
do {
let parsedJS = try jsondec.decode(Data1.self, from: data)
self.userData = parsedJS.data
}
Replace numberOfItems with
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return userData.count
}
and replace cellForItem with
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cellol = collectionView.dequeueReusableCell(withReuseIdentifier: "OfferCollectionViewCell", for: indexPath) as! OfferCollectionViewCell
let item = userData[indexPath.item]
if let image = item.image.first {
print(item.title, image)
// cellol.offerImageView.image = UIImage(
}
cellol.titleLabel.text = item.title
return cellol
}
Important note:
The value of image is a string representing a partial URL. It cannot be converted to an UIImage. You have to download the image separately.
Related
I'm new at programming at all, trying making app with country's info (capital, language, currencies etc.).
For now all working except one thing. I want make button to share text info about country. And at this place start's troubles, I can't write method to share my currencies and language info. I write func to capture one currency from each country, but I don't understand how to iterate through my currencies and languages, to get all values if country have more than 1 currency and language. I understand how to do it in my tableView method, using indexPath for this, but can't understand how do it this at another function. Sorry for my English :) It's not my native language.
I parse JSON from RestCountries. This is my struct to parse JSON:
struct Country: Codable {
let name: Name
let cca2: String
let capital: [String]?
let population: Int
let currencies: [String: Currency]?
let languages: [String: String]?
}
struct Name: Codable {
let common: String
let official: String
}
struct Currency: Codable {
let name: String?
let symbol: String?
}
This is my DetailViewController:
import UIKit
class DetailViewController: UITableViewController {
var country: Country!
let flag = "Flag"
let general = "General"
let currency = "Currency"
let language = "Languages"
var currencyText = ""
lazy var languages = country.languages?.sorted { $0.0 < $1.0 }
lazy var sectionTitles = [flag, general, currency, language]
lazy var currencies = country.currencies?.sorted { $0.0 < $1.0 }
override func viewDidLoad() {
super.viewDidLoad()
title = country.name.common
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareTapped))
}
override func numberOfSections(in tableView: UITableView) -> Int {
return sectionTitles.count
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sectionTitles[section]
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch sectionTitles[section] {
case flag:
return 1
case general:
return 4
case currency:
// How make to return proper number's of rows??
return currencies?.count ?? 0
case language:
return country.languages?.count ?? 0
default:
return 0
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch sectionTitles[indexPath.section] {
case flag:
let cell = tableView.dequeueReusableCell(withIdentifier: "Flag", for: indexPath)
if let cell = cell as? FlagCell {
cell.flagImageView.image = UIImage(named: country.cca2.lowercased())
}
return cell
case general:
let cell = tableView.dequeueReusableCell(withIdentifier: "Text", for: indexPath)
cell.textLabel?.numberOfLines = 0
switch indexPath.row {
case 0:
cell.textLabel?.text = "Common country name: \(country.name.common)"
case 1:
cell.textLabel?.text = "Official country name: \(country.name.official)"
case 2:
cell.textLabel?.text = "Capital: \(country.capital?[0] ?? "Unknown")"
case 3:
cell.textLabel?.text = "Population: \(country.population) people"
default:
return cell
}
return cell
case currency:
let cell = tableView.dequeueReusableCell(withIdentifier: "Text", for: indexPath)
cell.textLabel?.numberOfLines = 0
if let (code, currency) = currencies?[indexPath.row] {
let currencyCode = code
let currencyName = currency.name ?? ""
let currencySymbol = currency.symbol ?? ""
cell.textLabel?.text = "Code: \(currencyCode), Currency: \(currencyName), Symbol: \(currencySymbol)"
}
return cell
case language:
let cell = tableView.dequeueReusableCell(withIdentifier: "Text", for: indexPath)
cell.textLabel?.numberOfLines = 0
if let (_, language) = languages?[indexPath.row] {
cell.textLabel?.text = "Language: \(language)"
}
return cell
default:
break
}
return UITableViewCell ()
}
#objc func shareTapped () {
currenciesText()
let shareFlag = UIImage(named: country.cca2.lowercased())
let shareText = """
General
\(country.name.common)
\(country.name.official)
\(country.capital?[0] ?? "")
\(country.population)
Currencies
\(currencyText)
"""
let vc = UIActivityViewController(activityItems: [shareFlag!, shareText], applicationActivities: [])
vc.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
present(vc, animated: true)
}
func currenciesText () {
// How to make this work if country have more than 1 currency?
if let (code, currency) = currencies?[0] {
let currencyCode = code
let currencyName = currency.name ?? ""
let currencySymbol = currency.symbol ?? ""
currencyText = "\(currencyName) (\(currencyCode), \(currencySymbol))"
}
}
}
I'm totally lost in all this loops, this must be the way use for-in, but all things I try Xcode don't like :))) Please help! :)
my JSON:
https://www.cbr-xml-daily.ru/daily_json.js
my code:
struct CoinData: Decodable {
let Valute: [String: CoinInfo]
}
struct CoinInfo: Decodable {
let Name: String
let Value: Double
}
if let safeData = data {
if let coinData = self.parseJSON(safeData) {
print(coinData)
}
}
func parseJSON(_ data: Data) -> [String: CoinInfo]? {
let decoder = JSONDecoder()
do {
let decodedData = try decoder.decode(CoinData.self, from: data)
return decodedData.Valute
} catch {
delegate?.didFailWithError(error: error)
return nil
}
}
In debug console following gets printed:
["PLN": CurrencyConverter.CoinInfo(Name: "X", Value: 19.6678), ...]
This way I can't reach Name and Value properties of a coin. What's wrong?
I am going to do for-loop to check if a key contains certain symbols. If it does - I will need to be able to access to both Name and Value
You don't actually need a for loop. Since coinData is a dictionary, you can use its subscript, together with optional binding to do this. For example, to check if the key "PLN" exists, and access its name and value:
if let coinInfo = coinData["PLN"] {
print(coinInfo.Name)
print(coinInfo.Value)
} else {
// "PLN" does not exist
}
StoyBoard
Code
import UIKit
import Alamofire
// MARK: - CoinData
struct CoinData: Codable {
let date, previousDate: String
let previousURL: String
let timestamp: String
let valute: [String: Valute]
enum CodingKeys: String, CodingKey {
case date = "Date"
case previousDate = "PreviousDate"
case previousURL = "PreviousURL"
case timestamp = "Timestamp"
case valute = "Valute"
}
}
// MARK: - Valute
struct Valute: Codable {
let id, numCode, charCode: String
let nominal: Int
let name: String
let value, previous: Double
enum CodingKeys: String, CodingKey {
case id = "ID"
case numCode = "NumCode"
case charCode = "CharCode"
case nominal = "Nominal"
case name = "Name"
case value = "Value"
case previous = "Previous"
}
}
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
var getCoinData = [CoinData]()
var coinNameArr = [String]()
var coinDataArr = [Valute]()
#IBOutlet weak var tblDataList: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
getData()
}
func getData()
{
let url = "https://www.cbr-xml-daily.ru/daily_json.js"
AF.request(url, method: .get, encoding: URLEncoding.default).responseJSON { response in
let json = response.data
do{
let decoder = JSONDecoder()
self.getCoinData = [try decoder.decode(CoinData.self, from: json!)]
let response = self.getCoinData[0]
if response.valute.count != 0 {
self.coinNameArr.removeAll()
self.coinDataArr.removeAll()
for (coinName, coinData) in response.valute {
self.coinNameArr.append(coinName)
self.coinDataArr.append(coinData)
}
self.tblDataList.reloadData()
} else {
}
}catch let err{
print(err)
}
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return coinDataArr.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:coinTblCell = tableView.dequeueReusableCell(withIdentifier: "CellID", for: indexPath as IndexPath) as! coinTblCell
cell.accessoryType = .disclosureIndicator
cell.tintColor = .black
let rowData = coinDataArr[indexPath.row]
cell.lblName.text = rowData.name
cell.lblValue.text = String(rowData.value)
return cell
}
}
class coinTblCell: UITableViewCell {
#IBOutlet weak var lblName: UILabel!
#IBOutlet weak var lblValue: UILabel!
}
I am working on table view to render some data received after JSON parsing. I want my table view to have sections based on different dates. Each record in JSON is an event and multiple events can take place on single date.
Here is my JSON data
https://get.rosterbuster.com/wp-content/uploads/dummy-response.json
I want to render my table view like this
Table View with Sections as Date
What I have done sofar:
I have parsed the data in following Structure
struct Roster : Codable {
let flightnr: String?
let date: String?
let aircraftType: String?
let tail: String?
let departure: String?
let destination: String?
let departTime: String?
let arrivalTime: String?
let dutyID: String?
let dutyCode: String?
let captain: String?
let firstOfficer: String?
let flightAttendant: String?
enum CodingKeys: String, CodingKey {
case flightnr = "Flightnr"
case date = "Date"
case aircraftType = "Aircraft Type"
case tail = "Tail"
case departure = "Departure"
case destination = "Destination"
case departTime = "Time_Depart"
case arrivalTime = "Time_Arrive"
case dutyID = "DutyID"
case dutyCode = "DutyCode"
case captain = "Captain"
case firstOfficer = "First Officer"
case flightAttendant = "Flight Attendant"
}
}
I have also setup basic table view but don't know how to group the retrieved data into different sections as per the image I have attached above.
Any help would be appreciated.
This is the approach I'd suggest:
1) get number of sections by mapping the API JSON response in a set based on the date property. Here's something you could use (maybe you don't need to cast it in Array as well and you want to check if date is not nil)
self.sections = Array(Set(self.dataModel.map({ (roster) -> String in
roster.date!
})))
2) set your rowsPerSection data model by creating an array of Roster for each section.
//first set the array of sections.count dimension and empty array for each item
self.sections.forEach({ (string) in
self.rowsPerSection.append([])
})
//then set each array
for index in 0..<self.sections.count {
self.dataModel.forEach({ (roster) in
if roster.date == self.sections[index] {
self.rowsPerSection[index].append(roster)
}
})
}
This is my dummy code, I tested it with your URL and it works:
class ViewController: UIViewController {
#IBOutlet weak var tableView: UITableView!
var dataModel = [Roster]()
var sections = [String]()
var rowsPerSection = [[Roster]]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
APICall { (rosters) in
DispatchQueue.main.async {
self.dataModel = rosters!
self.sections = Array(Set(self.dataModel.map({ (roster) -> String in
roster.date!
})))
//first set the array of sections.count dimension and empty array for each item
self.sections.forEach({ (string) in
self.rowsPerSection.append([])
})
//then set each array
for index in 0..<self.sections.count {
self.dataModel.forEach({ (roster) in
if roster.date == self.sections[index] {
self.rowsPerSection[index].append(roster)
}
})
}
self.tableView.reloadData()
}
}
}
func APICall(onSuccess: #escaping(_ response: [Roster]?) -> Void) {
let group = DispatchGroup()
group.enter()
DispatchQueue.global(qos: .default).async {
let url = URL(string: "https://get.rosterbuster.com/wp-content/uploads/dummy-response.json")!
let requestURL = URLRequest(url: url)
let session = URLSession.shared
session.dataTask(with: requestURL) { (data, response, error) in
let decoder = JSONDecoder()
let responseJson = try! decoder.decode([Roster].self, from: data!)
onSuccess(responseJson)
group.leave()
}.resume()
group.wait()
return
}
}
}
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
for index in 0..<sections.count {
if index == section {
return rowsPerSection[index].count
}
}
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = rowsPerSection[indexPath.section] [indexPath.row].destination
return cell
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sections[section]
}
}
Here's the screenshot -> screenshot
cellForRow
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
-> UITableViewCell {
guard let cell =
tableView.dequeueReusableCell(withIdentifier: "EventsCell") as? EventsCell
else { return UITableViewCell() }
cell.homeLabel.text = events[indexPath.row].homeTeamName
cell.awayLabel.text = events[indexPath.row].awayTeamName
cell.homeGoalLbl.text =
String (describing: events[indexPath.row].result.goalsHomeTeam)
cell.awayGoalLbl.text =
String (describing: events[indexPath.row].result.goalsAwayTeam)
return cell
}
Codables
class EventsFull: Codable {
let fixtures: [EventsData]
init(fixtures: [EventsData]) {
self.fixtures = fixtures
}
}
class ResultsData: Codable {
let goalsHomeTeam: Int?
let goalsAwayTeam: Int?
init(goalsHomeTeam: Int,goalsAwayTeam: Int) {
self.goalsHomeTeam = goalsHomeTeam
self.goalsAwayTeam = goalsAwayTeam
}
}
class EventsData: Codable {
let date: String
let status: String
let matchday: Int
let homeTeamName: String
let awayTeamName: String
let result: ResultsData
let odds: Double?
init(date: String, status: String, matchday: Int, homeTeamName: String, awayTeamName: String, result: ResultsData, odds: Double) {
self.date = date
self.status = status
self.matchday = matchday
self.homeTeamName = homeTeamName
self.awayTeamName = awayTeamName
self.result = result
self.odds = odds
}
}
console:
downloaded
Optional(3)
Optional(2)
How to remove Optional from the view and how to "nil" does not appear?
If we get nil, what string should appear in the goals labels? You need to specify that. Then you can write this:
let ifnil = "" // or whatever the desired string is
cell.homeGoalLbl.text =
events[indexPath.row].result.goalsHomeTeam.flatMap {String($0)} ?? ifnil
cell.awayGoalLbl.text =
events[indexPath.row].result.goalsAwayTeam.flatMap {String($0)} ?? ifnil
That will do both jobs at once — it eliminates both "Optional" and "nil" as possible label values.
[See https://stackoverflow.com/a/42960286/341994.]
i am having trouble to reload my UICollectionview after i got my json data using TRON pod (it is like alamofire but in different structure i think)
and i parsed it using swiftyJSON
i am searching for the answer about three days and i dont know what i am missing
...
import UIKit
import SwiftyJSON
import TRON
class FeaturedAppViewController: UICollectionViewController ,
UICollectionViewDelegateFlowLayout {
private let cellID = "cellId"
var appCategories : [AppCategory]?
override func viewDidLoad() {
super.viewDidLoad()
fetchHomeApps()
collectionView?.backgroundColor = .white
collectionView?.register(CategoryCell.self, forCellWithReuseIdentifier: cellID)
}
class Home : JSONDecodable{
var apps : [App]
required init(json: JSON) throws {
print("now ready to parse :\n", json)
var apps = [App]()
let catJSON = json["categories"]
let array = json["categories"].array
for app in array!{
for index in 0...catJSON.count - 1 {
let name = app["apps"][index]["Name"].stringValue
let id = app["apps"][index]["Id"].intValue
let imageName = app["apps"][index]["ImageName"].stringValue
let category = app["apps"][index]["Category"].stringValue
let price = app["apps"][index]["Price"].doubleValue
let appsIdentification = App(iD: id, name: name, category: category, price: price, imageName: imageName)
apps.append(appsIdentification)
}
}
self.apps = apps
}
}
class JSONError : JSONDecodable {
required init(json: JSON) throws {
print("josn Error")
}
}
fileprivate func fetchHomeApps() {
print("123")
let request : APIRequest<AppCategory , JSONError> = tron.request("/appstore/featured")
request.perform(withSuccess: { (AppCategory) in
print("Successfully Fetched")
print(AppCategory.apps.count)
self.collectionview.reloaddata()
}) { (err) in
print("couldnt Fetch babe \n" , err)
}
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if let count = appCategories?.count {
return count
}else{
return 0
}
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath) as! CategoryCell
cell.appCategory = appCategories?[indexPath.item]
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width , height: 230)
}
let tron = TRON(baseURL: "http://www.statsallday.com")
}
this is my view controller and there is a models page
import UIKit
import SwiftyJSON
import TRON
class AppCategory : NSObject , JSONDecodable {
var name : String?
var type : String?
let Url = "http://www.statsallday.com/appstore/featured"
var apps : [App]
required init(json: JSON) throws {
print("now ready to parse :\n", json)
var apps = [App]()
let catJSON = json["categories"]
let array = json["categories"].array
for app in array!{
for index in 0...catJSON.count - 1 {
let name = app["apps"][index]["Name"].stringValue
let id = app["apps"][index]["Id"].intValue
let imageName = app["apps"][index]["ImageName"].stringValue
let category = app["apps"][index]["Category"].stringValue
let price = app["apps"][index]["Price"].doubleValue
let appsIdentification = App(iD: id, name: name, category: category, price: price, imageName: imageName)
apps.append(appsIdentification)
}
}
self.apps = apps
}
}
struct App {
let iD : Int
let name : String
let category : String
let price : Double
let imageName : String
}
i think i should add something in fetchHomeApps function but i dont know what...
actually i started programming since 34 days age and sorry if i my code is silly.
You should call self.yourCollectionView.reloadData() when you fetched data from API and parse with swiftyJson. Only when appCategories have data not empty array object.