Async Closure Issue Solve in Swift not working? - ios

I Have boiled down the problem to this
this closure :
override func viewDidLoad() {
super.viewDidLoad()
let data = homeDataSource()
getPrivatePosts { (posts) in
print("postsCOUNT" , posts!.count)
data.posts = posts!
}
self.datasource = data
collectionView?.reloadData()
}
prints out "postCOUNT 1 postCOUNT 3"
then when I print the count of data.posts I get 0... whats going on with that?? here is the full code
this is a custom UICollectionView:
import LBTAComponents
import Firebase
class homeView: DatasourceController {
override func viewDidLoad() {
super.viewDidLoad()
let data = homeDataSource()
getPrivatePosts { (posts) in
print("postsCOUNT" , posts!.count)
data.posts = posts!
}
self.datasource = data
collectionView?.reloadData()
}
override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width , height: 150)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSize(width: view.frame.width, height: 0 )
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
return CGSize(width: view.frame.width, height: 0)
}
// just to test
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
performSegue(withIdentifier: "goToNewPost", sender: self)
}
func getPrivatePosts(completion : #escaping (_ privatePosts : [Post]?) ->()){
// fill posts array with posts from all buddys "privataPosts only"
var ret = [Post]()
staticValuesForData.instance.dataBaseUserref.child((Auth.auth().currentUser?.uid)!).child("contacts").observe( .value , with: { (snapshot) in
let dict = snapshot.children.allObjects as! [DataSnapshot]
for d in dict{
if let contactUid = d.childSnapshot(forPath: "uid").value as? String{
staticValuesForData.instance.dataBaseUserref.child(contactUid).child("privatePosts").observe( .value, with: { (snapshot) in
let posts = snapshot.children.allObjects as! [DataSnapshot]
print("postval" , posts)
for post in posts{
if let dict = post.value as? [String : AnyObject]{
let fullname = dict["fullname"] as! String
let picUrl = dict["picUrl"] as! String
let postContent = dict["postContent"] as! String
let time = dict["time"] as! Int
let uid = dict["uid"] as! String
let username = dict["username"] as! String
print("first name of person who did the post" , fullname)
let reposts = dict["reposts"] as! [String]
let downs = dict["downs"] as! [String]
// possible issue
var comments = [Comment]()
let commentArr = snapshot.childSnapshot(forPath: "comments").children.allObjects as! [DataSnapshot]
for c in commentArr{
if let dict = c.value as? [String : AnyObject]{
let cuid = dict["uid"] as! String
let ccommentText = dict["commentText"] as! String
let cpicUrl = dict["picUrl"] as! String
let cusername = dict["username"] as! String
let ctime = dict["time"] as! Int
let com = Comment(uid: cuid, commentText: ccommentText, time: ctime, picUrl: cpicUrl, username: cusername)
comments.append(com)
}
}
print("HERE : post content\(postContent) username : \(username) commentArr \(comments)")
let postToAdd = Post(postContent: postContent, picUrl: picUrl, userName: username, fullName: fullname, postID: uid, postTime: time, downs: downs, reposts: reposts, comments: comments)
print("LOOK AT MEE \(postToAdd.userName) is the username of the post object \(postToAdd.postContent) is the contetn")
ret.append(postToAdd)
print("RET" , ret)
}
}
completion(ret) // this is where the completion block should be called
})
}
}
})
}
}
This is a datasource object :
import LBTAComponents
class homeDataSource: Datasource {
var posts = [Post]()
override func numberOfItems(_ section: Int) -> Int {
print("COUNT " , posts.count)
return posts.count
}
override func headerClasses() -> [DatasourceCell.Type]? {
return [userHeader.self]
}
override func footerClasses() -> [DatasourceCell.Type]? {
return [userFooter.self]
}
override func cellClasses() -> [DatasourceCell.Type] {
return [userCell.self]
}
override func item(_ indexPath: IndexPath) -> Any? {
return posts[indexPath.item]
}
}
The frame work can be used here :
pod 'LBTAComponents'

You have the same basic misunderstanding twice.
In the second code section you create your ret variable initially empty and then fire of some async tasks. However you call the completion(ret) outside of the async task so it will fire immediately before the async tasks have finished and therefore return your initial empty value.
The fist code also will suffer the same problem in that you create your postArray initially empty then call your getPrivatePosts function supplying a completion handler but that completion handler will be called in an async task so there could be a delay but you use the value immediately and therefore will return the empty initial value.

You shouldn't create your posts array in that way. You should create the a mutable array:
var posts = [Post]()
Then in the viewDidLoad of your view controller you should then populate the array from your service (Firebase).
override func viewDidLoad() {
super.viewDidLoad()
getPrivatePosts() { posts in
self.posts = posts ?? []
}
}
You posts function also is never going to return the data you want from the service since your calling your completion block outside of the scope of the service request. Move the completion block to the bottom of the for loop in the staticValuesForData.instance.dataBaseUserref.child part of the getPrivatePosts function like so:
class func getPrivatePosts(completion : (_ privatePosts : [Post]?) ->. ()){
// fill posts array with posts from all buddys "privataPosts only"
var ret = [Post]()
staticValuesForData.instance.dataBaseUserref.child((Auth.auth().currentUser?.uid)!).child("contacts").observe( .value , with: { (snapshot) in
let dict = snapshot.children.allObjects as! [DataSnapshot]
for d in dict{
if let contactUid = d.childSnapshot(forPath: "uid").value as? String{
staticValuesForData.instance.dataBaseUserref.child(contactUid).child("privatePosts").observe( .value, with: { (snapshot) in
let posts = snapshot.children.allObjects as! [DataSnapshot]
print("postval" , posts)
for post in posts{
if let dict = post.value as? [String : AnyObject]{
let fullname = dict["fullname"] as! String
let picUrl = dict["picUrl"] as! String
let postContent = dict["postContent"] as! String
let time = dict["time"] as! Int
let uid = dict["uid"] as! String
let username = dict["username"] as! String
print("first name of person who did the post" , fullname)
let reposts = dict["reposts"] as! [String]
let downs = dict["downs"] as! [String]
// possible issue
var comments = [Comment]()
let commentArr = snapshot.childSnapshot(forPath: "comments").children.allObjects as! [DataSnapshot]
for c in commentArr{
if let dict = c.value as? [String : AnyObject]{
let cuid = dict["uid"] as! String
let ccommentText = dict["commentText"] as! String
let cpicUrl = dict["picUrl"] as! String
let cusername = dict["username"] as! String
let ctime = dict["time"] as! Int
let com = Comment(uid: cuid, commentText: ccommentText, time: ctime, picUrl: cpicUrl, username: cusername)
comments.append(com)
}
}
print("HERE : post content\(postContent) username : \(username) commentArr \(comments)")
let postToAdd = Post(postContent: postContent, picUrl: picUrl, userName: username, fullName: fullname, postID: uid, postTime: time, downs: downs, reposts: reposts, comments: comments)
print("LOOK AT MEE \(postToAdd.userName) is the username of the post object \(postToAdd.postContent) is the contetn")
ret.append(postToAdd)
print("RET" , ret)
}
}
completion(ret) // this is where the completion block should be called
})
}
}
})
}
I hope this helps.

Related

Fetching Image Url's From Realtime Database - Firebase / Swift

I am trying to display images onto a collection view. The image url's are saved in the realtime database in Firebase and was wondering, what I am doing wrong? Essentially, users have a node called 'Images' where images they have uploaded are saved inside that node. The names depend on the image Title and the url is the image they have uploaded. Below is my code and a photo of how my database looks like it. If someone could help me out, I would appreciate that a lot. Thanks!
The Issue is that the images are not being displayed. It is successfully able to display the correct amount of images the user has in their account but does not read the image url. My guess is that because each url is under a different value (imageTitle). Any ideas?
My ViewController:
class PicturesViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
#IBOutlet weak var imageCollection: UICollectionView!
var customImageFlowLayout: CustomImageFlowLayout!
var images = [UserImages]()
var dbRef: DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
dbRef = Database.database().reference().child("users/\(Auth.auth().currentUser!.uid)/Images")
loadDB()
}
func loadDB() {
dbRef.observe(DataEventType.value, with: { (snapshot) in
var newImages = [UserImages]()
for UserImagesSnapshot in snapshot.children {
let UserImagesObject = UserImages(snapshot: UserImagesSnapshot as! DataSnapshot)
newImages.append(UserImagesObject)
}
self.images = newImages
self.imageCollection.reloadData()
})
}
func collectionView(_ imageCollection: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return images.count
}
func collectionView(_ imageCollection: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = imageCollection.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! ImageCollectionViewCell
let image = images[indexPath.row]
cell.imageView.sd_setImage(with: URL(string: image.url), placeholderImage: UIImage(named: "image1"))
return cell
}
My Array - UserImages
struct UserImages {
let key: String!
let url: String!
let itemsRef: DatabaseReference!
init (url:String, key:String) {
self.key = key
self.url = url
self.itemsRef = nil
}
init(snapshot: DataSnapshot) {
key = snapshot.key
itemsRef = snapshot.ref
let snapshotValue = snapshot.value as? NSDictionary
if let imageUrl = snapshotValue?[""] as? String {
url = imageUrl
} else {
url = ""
}
}
}
Replace
let snapshotValue = snapshot.value as? NSDictionary
if let imageUrl = snapshotValue?[""] as? String {
url = imageUrl
} else {
url = ""
}
with
url = snapshot.value as! String

Swift Firebase "Cannot assign value of type 'Information' to type 'NSDictionary?'"

I have a tableview that is being populated with who a user is following. Problem is that I need to pass that cells data to "var otherUser: NSDictionary!" but because I am populating the cell using a data structure file called "Information" I get this error - "Cannot assign value of type 'Information' to type 'NSDictionary?'" in the prepareForSegue. I am unsure if I can repackage the information I need into a NSDictionary so I can successfully do a data pass. I just don't know if this is a easy solution or an actual problem because of my ignorance.
Following TableViewController Code
import UIKit
import Firebase
class BusinessFollowing: UITableViewController {
#IBOutlet var noDataView: UIView!
#IBOutlet var followingTableView: UITableView!
var yourFollowing = [Information]()
var listFollowing = [NSDictionary?]()
var databaseRef = Database.database().reference()
let uid = Auth.auth().currentUser?.uid
var loggedInUser = Auth.auth().currentUser
var loggedInUserData:NSDictionary?
var following = [String]()
override func viewDidLoad() {
super.viewDidLoad()
self.followingTableView.backgroundView = nil
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.followingTableView.reloadData()
self.yourFollowing.removeAll()
self.following.removeAll()
getFollowingData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
if segue.identifier == "following" {
// gotta check if we're currently searching
if let indexPath = followingTableView.indexPathForSelectedRow {
let user = self.yourFollowing[indexPath.row]
let controller = segue.destination as? ExploreBusinessProfileSwitchView
controller?.otherUser = user
}
}
}
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return self.yourFollowing.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! BusinessFollowingCell
let following = yourFollowing[indexPath.row]
let businessName = following.businessName
let businessStreet = following.businessStreet
let businessCity = following.businessCity
let businessState = following.businessState
cell.businessName.text = businessName
cell.businessStreet.text = businessStreet
cell.businessCity.text = businessCity
cell.businessState.text = businessState
// cell.businessName?.text = self.listFollowing[indexPath.row]?["businessName"] as? String
// cell.businessStreet?.text = self.listFollowing[indexPath.row]?["businessStreet"] as? String
// cell.businessCity?.text = self.listFollowing[indexPath.row]?["businessCity"] as? String
// cell.businessState?.text = self.listFollowing[indexPath.row]?["businessState"] as? String
return cell
}
func getFollowingData() {
self.yourFollowing.removeAll()
self.following.removeAll()
self.followingTableView.reloadData()
Database.database().reference().child("Businesses").child((loggedInUser?.uid)!).child("following").observe(.value, with: { snapshot in
if snapshot.exists() {
MBProgressHUD.showAdded(to: self.view, animated: true)
let databaseRef = Database.database().reference()
databaseRef.child("Businesses").queryOrderedByKey().observeSingleEvent(of: .value, with: { (usersSnapshot) in
let users = usersSnapshot.value as! [String: AnyObject]
for (_, value) in users {
if let userID = value["uid"] as? String {
if userID == Auth.auth().currentUser?.uid {
print(value)
if let followingUsers = value["following"] as? [String : String] {
for (_,user) in followingUsers {
self.following.append(user)
}
}
databaseRef.child("following").queryOrderedByKey().observeSingleEvent(of: .value, with: { (postsSnapshot) in
let posts = postsSnapshot.value as! [String: AnyObject]
for (_, post) in posts {
for (_, postInfo) in post as! [String: AnyObject] {
if let followingID = postInfo["uid"] as? String {
for each in self.following {
if each == followingID {
guard let uid = postInfo["uid"] as! String? else {return}
guard let name = postInfo["businessName"] as! String? else {return}
guard let address = postInfo["businessStreet"] as! String? else {return}
guard let state = postInfo["businessState"] as! String? else {return}
guard let city = postInfo["businessCity"] as! String? else {return}
self.yourFollowing.append(Information(uid: uid, businessName: name, businessStreet: address, businessCity: city, businessState: state))
}
self.followingTableView.backgroundView = nil
self.followingTableView.reloadData()
}
}
}
}
MBProgressHUD.hide(for: self.view, animated: true)
}) { (error) in
print(error.localizedDescription)
}
}
}
}
})
} else {
print("Not following anyone")
self.followingTableView.backgroundView = self.noDataView
MBProgressHUD.hide(for: self.view, animated: true)
}
})
}
}
"Information" Data Structure File
import UIKit
class Information {
var uid: String
var businessName: String
var businessStreet: String
var businessCity: String
var businessState: String
init(uid: String, businessName: String, businessStreet: String, businessCity: String, businessState: String){
self.uid = uid
self.businessName = businessName
self.businessStreet = businessStreet
self.businessCity = businessCity
self.businessState = businessState
}
}
The error is pretty clear.
user in ExploreBusinessProfileSwitchView is obviously declared as NSDictionary, declare it as Information.
By the way don't use NSArray / NSDictionary in Swift. Use native types.

custom class data not showing in to the tableview in swift

hi am fetching from data from firebase and stored into custom class and displaying into the tableview, when I displaying tableview its not showing empty but when I am calling with another array data its working fine
class datapass {
var fullName : String?
var status : String?
var dateAndTimeofVisit :String?
var profilephot :String?
var uid :String?
var inviterUID: String?
init(fullname:String?,status:String?,dateAndTimeofVisit:String?,profilephot:String,uid:String?,inviterUID:String?) {
self.fullName = fullname
self.status = status
self.dateAndTimeofVisit = dateAndTimeofVisit
self.profilephot = profilephot
self.uid = uid
self.inviterUID = inviterUID
}
}
inside viewdidload
var datapassval = [datapass]()
HandedDataRef = Database.database().reference()
.child(Constants.FIREBASE_CHILD_VISITORS)
.child(Constants.FIREBASE_CHILD_PRE_APPROVED_VISITORS).child("-LHO1TuRZTKCZV5Mli13")
HandedDataRef?.observeSingleEvent(of: .value, with: {(snapshot) in
print("snapshot values",snapshot)
if snapshot.exists() {
let visitorData = snapshot.value as? [String: AnyObject]
print("visitordata",visitorData as Any)
let dateAndTimeOfVisit = visitorData?[VisitorListFBKeys.dateAndTimeOfVisit.key] as? String
let fullName = visitorData?[VisitorListFBKeys.fullName.key] as? String
let inviterUID = visitorData?[VisitorListFBKeys.inviterUID.key] as? String
let mobileNumber = visitorData?[VisitorListFBKeys.mobileNumber.key] as? String
let profilePhoto = visitorData?[VisitorListFBKeys.profilePhoto.key] as? String
let status = visitorData?[VisitorListFBKeys.status.key] as? String
let uid = visitorData?[VisitorListFBKeys.uid.key] as? String
self.datapassval.append(datapass.init(fullname: fullName, status: status , dateAndTimeofVisit: dateAndTimeOfVisit, profilephot: profilePhoto!, uid: uid, inviterUID: inviterUID))
}
})
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return datapassval.count //count getting 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! HandedThingsToGuestTableViewCell
let datamy = datapassval[indexPath.row]
print("datamy",datamy)
cell.lbl_VisiterName.text = datamy.fullName
}
its not showing any thing how to display custom class data where I did mistake
You need to reload the table
self.datapassval.append(datapass.init(fullname: fullName, status: status , dateAndTimeofVisit: dateAndTimeOfVisit, profilephot: profilePhoto!, uid: uid, inviterUID: inviterUID))
self.tableView.reloadData()

Not able to save data from Firebase database to an Array

*I'm fairly new to swift
I'm currently using Swift 4, Xcode 9, and Firebase. My goal is to create an app that stores data in a list, displays it in a table view, and allows the user to add more data to the list. I'm stuck on the displaying data part, I created a function that is supposed to get the data from the database, then add it into an array so that I can display individual parts of it on a custom table view cell. Here's my code:
class OrdersPage: UIViewController, UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return orders.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "orderCell", for: indexPath) as! OrderCell
cell.setOrder(order: orders[indexPath.row])
print("Adding new cell")
return cell
}
#IBOutlet weak var tableView: UITableView!
var ref: DatabaseReference!
var orders = [Order]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
self.ref = Database.database().reference()
orders = getOrders()
}
func getOrders() -> [Order] {
var tempArray = [Order]()
ref.child("Orders").observe(.value) { (snapshot) in
for child in snapshot.children {
let orderDB = child as! DataSnapshot
let orderDict = orderDB.value as! [String: Any]
let name = orderDict["name"] as! String
let date = orderDict["date"] as! String
let time = orderDict["time"] as! String
let hotel = orderDict["hotel"] as! String
let room = orderDict["room"] as! String
let airport = orderDict["airport"] as! String
let agent = orderDict["agent"] as! String
let price = orderDict["price"] as! String
//let submitted = orderDict["submitted"] as! String
tempArray.append(Order(name: name, date: date, time: time, hotel: hotel, room: room, airport: airport, agent: agent, price: price))
}
}
return tempArray
}
Based off of my testing, the issue is that the orders array doesn't contain anything when the numberOfRowsInSection is called so it doesn't create any cells in the table view. I'm not sure why it's not working as it should and have been stuck on this for quite some time now, any help is appreciated.
getOrders() is Asynchronous call so you need to reload your table after you got data from server.
Here is the way you can achieve that.
Replace:
func getOrders() -> [Order]
with
func getOrders()
And your getOrders method will look like:
func getOrders() {
ref.child("Orders").observe(.value) { (snapshot) in
for child in snapshot.children {
let orderDB = child as! DataSnapshot
let orderDict = orderDB.value as! [String: Any]
let name = orderDict["name"] as! String
let date = orderDict["date"] as! String
let time = orderDict["time"] as! String
let hotel = orderDict["hotel"] as! String
let room = orderDict["room"] as! String
let airport = orderDict["airport"] as! String
let agent = orderDict["agent"] as! String
let price = orderDict["price"] as! String
//let submitted = orderDict["submitted"] as! String
//Add your data into array
self.orders.append(Order(name: name, date: date, time: time, hotel: hotel, room: room, airport: airport, agent: agent, price: price))
}
//Reload your tableView here
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}
I have updated inner code. Check comments.
Now in your viewDidLoad method Replace:
orders = getOrders()
With
getOrders()
You can use didSet during define your variable of self.orders for reloading UITableView
Here your table will automatically reload when any data is assigned to self.orders
Replace your declaration
var orders = [Order]()
with below code
var orders : [Order] = [] {
didSet {
tableView.reloadData()
}
}

Use Class / Struct in collectionCell inside collectionCell for future pass data

How do I properly load the array (image, image2, image3) images from my class Model in collectionCell?
The class itself Model looks like this:
class Model {
var image: String
var image2: String
var image3: String
var images: [String] = []
var images2: [String] = []
var images3: [String] = []
var ref: FIRDatabaseReference!
init(snapshot: FIRDataSnapshot) {
ref = snapshot.ref
let value = snapshot.value as! NSDictionary
let snap = value["hall1"] as? NSDictionary
let snap2 = value["hall2"] as? NSDictionary
let snap3 = value["hall3"] as? NSDictionary
image = snap?["qwerty"] as? String ?? ""
image2 = snap2?["qwerty"] as? String ?? ""
image3 = snap3?["qwerty"] as? String ?? ""
if let post1 = snap as? [String: AnyObject] {
for (_, value) in post1["images"] as! [String: AnyObject] {
self.images.append(value as! String)
}
}
if let post2 = snap2 as? [String: AnyObject] {
for (_, value) in post2["images"] as! [String: AnyObject] {
self.images2.append(value as! String)
}
}
if let post3 = snap3 as? [String: AnyObject] {
for (_, value) in post3["images"] as! [String: AnyObject] {
self.images3.append(value as! String)
}
}
}
}
In my collectionCell loaded only the first image, I basically understand why, as I understand it is due to the fact that sd_setImage does not display arrays (correct me if I'm wrong), but how to fix it can not figure out.
Code of the collectionCell:
class CollectionViewCell11: UICollectionViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
var imagess: [Model] = []
#IBOutlet weak var collectionView: UICollectionView!
var vc1: ViewController?
override func awakeFromNib() {
super.awakeFromNib()
collectionView.delegate = self
collectionView.dataSource = self
}
func collectionView(_ collectionView: UICollectionView, numb erOfItemsInSection section: Int) -> Int {
return imagess.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CollectionViewCell12
cell.imageView.sd_setImage(with: URL(string: imagess[indexPath.item].image))
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if vc1 != nil {
let vc2 = vc1!.storyboard?.instantiateViewController(withIdentifier: "ViewController2") as! ViewController2
vc2.photo = [imagess[indexPath.item]]
let backItem = UIBarButtonItem()
backItem.title = ""
vc1!.navigationItem.backBarButtonItem = backItem
vc1!.navigationController?.pushViewController(vc2, animated: true)
}
}
}
To use I need only the class Model, because it contains another array of images which I plan to display the next controller for scroll image.
If your next ViewController is a child of this cell then you can pass the array on to it this way.
You write this in the viewDidLoad() of the next ViewController:
var newImagesArray: [Model] = []
if let parentVC = self.parent as? CollectionViewCell11 {
newImagesArray = parentVC.imagess
}

Resources