Posts Being Uploaded Randomly in Collection View - Swift & Firebase
I have been refactoring my code and now I'm having trouble with the posts.
Whenever I add a new post to the collection view, it is being added in a random cell and out of order, instead of in the first post.
I know the reason is the fetchuser function and from what I'm being told due to the asynchronous loading, but don't know what to do in order to correct this.
Could someone help me figure out what to do so that my posts are added in the first cell?
@objc func observePostsAdoption()
let postsRef = Database.database().reference().child("posts")
postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value) (snapshot) in
var tempPost = [Posts]()
for child in snapshot.children
if let childSnapshot = child as? DataSnapshot
let dict = childSnapshot.value as? [String: Any]
let newAdoptiondPost = Posts.transformPost(dict: dict!)
//This will look up all users at once
self.fetchUser(userid: newAdoptiondPost.userid!, completed:
tempPost.insert(newAdoptiondPost, at: 0)
DispatchQueue.main.async
self.postsadoption = tempPost
self.adoptionCollectionView.reloadData()
self.refresherAdoption.endRefreshing()
)
func fetchUser(userid: String, completed: @escaping ()-> Void )
Database.database().reference().child("users").child(userid).observeSingleEvent(of: .value) (snapshot) in
if let dict = snapshot.value as? [String: Any]
let user = UserProfile.transformUser(dict: dict)
self.users.insert(user, at: 0)
completed()
Here's my Post Struct
class Posts
//UserView
var uid: String?
var author: UserProfile?
var timestamp: Date?
var userid: String?
func getDateFormattedString() -> String
let formatter = DateFormatter()
formatter.dateFormat = "MMM d, HH:mm"
return formatter.string(from: self.timestamp!)
//Image
var photoUrl: URL?
//PostInformation View
var city: String?
var municipality: String?
var name: String?
var breed : String?
var phone : String?
var address : String?
var petType: String?
var genderType: String?
var comments: String?
extension Posts
static func transformPost(dict: [String: Any]) -> Posts
let post = Posts()
//Post Picture
let photoUrl = dict["photoUrl"] as? String
post.photoUrl = URL(string: photoUrl!)
//INFO POSTS
post.userid = dict["userid"] as? String
post.city = dict["city"] as? String
post.municipality = dict["municipality"] as? String
post.name = dict["name"] as? String
post.breed = dict["breed"] as? String
post.phone = dict["phone"] as? String
post.address = dict["address"] as? String
post.comments = dict["comments"] as? String
post.petType = dict["petType"] as? String
post.genderType = dict["gender"] as? String
let timestamp = dict["timestamp"] as? Double
post.timestamp = Date(timeIntervalSince1970: timestamp!/1000)
return post
swift firebase asynchronous uicollectionview uicollectionviewcell
|
show 6 more comments
I have been refactoring my code and now I'm having trouble with the posts.
Whenever I add a new post to the collection view, it is being added in a random cell and out of order, instead of in the first post.
I know the reason is the fetchuser function and from what I'm being told due to the asynchronous loading, but don't know what to do in order to correct this.
Could someone help me figure out what to do so that my posts are added in the first cell?
@objc func observePostsAdoption()
let postsRef = Database.database().reference().child("posts")
postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value) (snapshot) in
var tempPost = [Posts]()
for child in snapshot.children
if let childSnapshot = child as? DataSnapshot
let dict = childSnapshot.value as? [String: Any]
let newAdoptiondPost = Posts.transformPost(dict: dict!)
//This will look up all users at once
self.fetchUser(userid: newAdoptiondPost.userid!, completed:
tempPost.insert(newAdoptiondPost, at: 0)
DispatchQueue.main.async
self.postsadoption = tempPost
self.adoptionCollectionView.reloadData()
self.refresherAdoption.endRefreshing()
)
func fetchUser(userid: String, completed: @escaping ()-> Void )
Database.database().reference().child("users").child(userid).observeSingleEvent(of: .value) (snapshot) in
if let dict = snapshot.value as? [String: Any]
let user = UserProfile.transformUser(dict: dict)
self.users.insert(user, at: 0)
completed()
Here's my Post Struct
class Posts
//UserView
var uid: String?
var author: UserProfile?
var timestamp: Date?
var userid: String?
func getDateFormattedString() -> String
let formatter = DateFormatter()
formatter.dateFormat = "MMM d, HH:mm"
return formatter.string(from: self.timestamp!)
//Image
var photoUrl: URL?
//PostInformation View
var city: String?
var municipality: String?
var name: String?
var breed : String?
var phone : String?
var address : String?
var petType: String?
var genderType: String?
var comments: String?
extension Posts
static func transformPost(dict: [String: Any]) -> Posts
let post = Posts()
//Post Picture
let photoUrl = dict["photoUrl"] as? String
post.photoUrl = URL(string: photoUrl!)
//INFO POSTS
post.userid = dict["userid"] as? String
post.city = dict["city"] as? String
post.municipality = dict["municipality"] as? String
post.name = dict["name"] as? String
post.breed = dict["breed"] as? String
post.phone = dict["phone"] as? String
post.address = dict["address"] as? String
post.comments = dict["comments"] as? String
post.petType = dict["petType"] as? String
post.genderType = dict["gender"] as? String
let timestamp = dict["timestamp"] as? Double
post.timestamp = Date(timeIntervalSince1970: timestamp!/1000)
return post
swift firebase asynchronous uicollectionview uicollectionviewcell
If your Post object has a property such as timestamp it will be very easy to do sorting. Can you show your Posts struct?
– Galo Torres Sevilla
Nov 16 '18 at 12:57
Hey Galo! I've added it to the question.
– Code With Xime
Nov 16 '18 at 13:25
Also, the thing is that I need to sort by "postType" for in this case adoption, because I have several other postTypes such as lost and found. Can I sort by the two different types? Timestamp AND postType?
– Code With Xime
Nov 16 '18 at 13:26
What exactly do you mean postType? I don't see any property where the postType is set.
– Galo Torres Sevilla
Nov 16 '18 at 14:15
Check in the first function. The observePostsAdoption. The postType is in Firebase --> let postsRef = Database.database().reference().child("posts") postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value)
– Code With Xime
Nov 16 '18 at 17:51
|
show 6 more comments
I have been refactoring my code and now I'm having trouble with the posts.
Whenever I add a new post to the collection view, it is being added in a random cell and out of order, instead of in the first post.
I know the reason is the fetchuser function and from what I'm being told due to the asynchronous loading, but don't know what to do in order to correct this.
Could someone help me figure out what to do so that my posts are added in the first cell?
@objc func observePostsAdoption()
let postsRef = Database.database().reference().child("posts")
postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value) (snapshot) in
var tempPost = [Posts]()
for child in snapshot.children
if let childSnapshot = child as? DataSnapshot
let dict = childSnapshot.value as? [String: Any]
let newAdoptiondPost = Posts.transformPost(dict: dict!)
//This will look up all users at once
self.fetchUser(userid: newAdoptiondPost.userid!, completed:
tempPost.insert(newAdoptiondPost, at: 0)
DispatchQueue.main.async
self.postsadoption = tempPost
self.adoptionCollectionView.reloadData()
self.refresherAdoption.endRefreshing()
)
func fetchUser(userid: String, completed: @escaping ()-> Void )
Database.database().reference().child("users").child(userid).observeSingleEvent(of: .value) (snapshot) in
if let dict = snapshot.value as? [String: Any]
let user = UserProfile.transformUser(dict: dict)
self.users.insert(user, at: 0)
completed()
Here's my Post Struct
class Posts
//UserView
var uid: String?
var author: UserProfile?
var timestamp: Date?
var userid: String?
func getDateFormattedString() -> String
let formatter = DateFormatter()
formatter.dateFormat = "MMM d, HH:mm"
return formatter.string(from: self.timestamp!)
//Image
var photoUrl: URL?
//PostInformation View
var city: String?
var municipality: String?
var name: String?
var breed : String?
var phone : String?
var address : String?
var petType: String?
var genderType: String?
var comments: String?
extension Posts
static func transformPost(dict: [String: Any]) -> Posts
let post = Posts()
//Post Picture
let photoUrl = dict["photoUrl"] as? String
post.photoUrl = URL(string: photoUrl!)
//INFO POSTS
post.userid = dict["userid"] as? String
post.city = dict["city"] as? String
post.municipality = dict["municipality"] as? String
post.name = dict["name"] as? String
post.breed = dict["breed"] as? String
post.phone = dict["phone"] as? String
post.address = dict["address"] as? String
post.comments = dict["comments"] as? String
post.petType = dict["petType"] as? String
post.genderType = dict["gender"] as? String
let timestamp = dict["timestamp"] as? Double
post.timestamp = Date(timeIntervalSince1970: timestamp!/1000)
return post
swift firebase asynchronous uicollectionview uicollectionviewcell
I have been refactoring my code and now I'm having trouble with the posts.
Whenever I add a new post to the collection view, it is being added in a random cell and out of order, instead of in the first post.
I know the reason is the fetchuser function and from what I'm being told due to the asynchronous loading, but don't know what to do in order to correct this.
Could someone help me figure out what to do so that my posts are added in the first cell?
@objc func observePostsAdoption()
let postsRef = Database.database().reference().child("posts")
postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value) (snapshot) in
var tempPost = [Posts]()
for child in snapshot.children
if let childSnapshot = child as? DataSnapshot
let dict = childSnapshot.value as? [String: Any]
let newAdoptiondPost = Posts.transformPost(dict: dict!)
//This will look up all users at once
self.fetchUser(userid: newAdoptiondPost.userid!, completed:
tempPost.insert(newAdoptiondPost, at: 0)
DispatchQueue.main.async
self.postsadoption = tempPost
self.adoptionCollectionView.reloadData()
self.refresherAdoption.endRefreshing()
)
func fetchUser(userid: String, completed: @escaping ()-> Void )
Database.database().reference().child("users").child(userid).observeSingleEvent(of: .value) (snapshot) in
if let dict = snapshot.value as? [String: Any]
let user = UserProfile.transformUser(dict: dict)
self.users.insert(user, at: 0)
completed()
Here's my Post Struct
class Posts
//UserView
var uid: String?
var author: UserProfile?
var timestamp: Date?
var userid: String?
func getDateFormattedString() -> String
let formatter = DateFormatter()
formatter.dateFormat = "MMM d, HH:mm"
return formatter.string(from: self.timestamp!)
//Image
var photoUrl: URL?
//PostInformation View
var city: String?
var municipality: String?
var name: String?
var breed : String?
var phone : String?
var address : String?
var petType: String?
var genderType: String?
var comments: String?
extension Posts
static func transformPost(dict: [String: Any]) -> Posts
let post = Posts()
//Post Picture
let photoUrl = dict["photoUrl"] as? String
post.photoUrl = URL(string: photoUrl!)
//INFO POSTS
post.userid = dict["userid"] as? String
post.city = dict["city"] as? String
post.municipality = dict["municipality"] as? String
post.name = dict["name"] as? String
post.breed = dict["breed"] as? String
post.phone = dict["phone"] as? String
post.address = dict["address"] as? String
post.comments = dict["comments"] as? String
post.petType = dict["petType"] as? String
post.genderType = dict["gender"] as? String
let timestamp = dict["timestamp"] as? Double
post.timestamp = Date(timeIntervalSince1970: timestamp!/1000)
return post
swift firebase asynchronous uicollectionview uicollectionviewcell
swift firebase asynchronous uicollectionview uicollectionviewcell
edited Nov 16 '18 at 13:25
Code With Xime
asked Nov 15 '18 at 20:26
Code With XimeCode With Xime
34
34
If your Post object has a property such as timestamp it will be very easy to do sorting. Can you show your Posts struct?
– Galo Torres Sevilla
Nov 16 '18 at 12:57
Hey Galo! I've added it to the question.
– Code With Xime
Nov 16 '18 at 13:25
Also, the thing is that I need to sort by "postType" for in this case adoption, because I have several other postTypes such as lost and found. Can I sort by the two different types? Timestamp AND postType?
– Code With Xime
Nov 16 '18 at 13:26
What exactly do you mean postType? I don't see any property where the postType is set.
– Galo Torres Sevilla
Nov 16 '18 at 14:15
Check in the first function. The observePostsAdoption. The postType is in Firebase --> let postsRef = Database.database().reference().child("posts") postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value)
– Code With Xime
Nov 16 '18 at 17:51
|
show 6 more comments
If your Post object has a property such as timestamp it will be very easy to do sorting. Can you show your Posts struct?
– Galo Torres Sevilla
Nov 16 '18 at 12:57
Hey Galo! I've added it to the question.
– Code With Xime
Nov 16 '18 at 13:25
Also, the thing is that I need to sort by "postType" for in this case adoption, because I have several other postTypes such as lost and found. Can I sort by the two different types? Timestamp AND postType?
– Code With Xime
Nov 16 '18 at 13:26
What exactly do you mean postType? I don't see any property where the postType is set.
– Galo Torres Sevilla
Nov 16 '18 at 14:15
Check in the first function. The observePostsAdoption. The postType is in Firebase --> let postsRef = Database.database().reference().child("posts") postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value)
– Code With Xime
Nov 16 '18 at 17:51
If your Post object has a property such as timestamp it will be very easy to do sorting. Can you show your Posts struct?
– Galo Torres Sevilla
Nov 16 '18 at 12:57
If your Post object has a property such as timestamp it will be very easy to do sorting. Can you show your Posts struct?
– Galo Torres Sevilla
Nov 16 '18 at 12:57
Hey Galo! I've added it to the question.
– Code With Xime
Nov 16 '18 at 13:25
Hey Galo! I've added it to the question.
– Code With Xime
Nov 16 '18 at 13:25
Also, the thing is that I need to sort by "postType" for in this case adoption, because I have several other postTypes such as lost and found. Can I sort by the two different types? Timestamp AND postType?
– Code With Xime
Nov 16 '18 at 13:26
Also, the thing is that I need to sort by "postType" for in this case adoption, because I have several other postTypes such as lost and found. Can I sort by the two different types? Timestamp AND postType?
– Code With Xime
Nov 16 '18 at 13:26
What exactly do you mean postType? I don't see any property where the postType is set.
– Galo Torres Sevilla
Nov 16 '18 at 14:15
What exactly do you mean postType? I don't see any property where the postType is set.
– Galo Torres Sevilla
Nov 16 '18 at 14:15
Check in the first function. The observePostsAdoption. The postType is in Firebase --> let postsRef = Database.database().reference().child("posts") postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value)
– Code With Xime
Nov 16 '18 at 17:51
Check in the first function. The observePostsAdoption. The postType is in Firebase --> let postsRef = Database.database().reference().child("posts") postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value)
– Code With Xime
Nov 16 '18 at 17:51
|
show 6 more comments
1 Answer
1
active
oldest
votes
If you already have the posts ordered by post type you can just do sorting depending on the timestamp. For example
@objc func observePostsAdoption()
let postsRef = Database.database().reference().child("posts")
postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value) (snapshot) in
var tempPost = [Posts]()
for child in snapshot.children
if let childSnapshot = child as? DataSnapshot
let dict = childSnapshot.value as? [String: Any]
let newAdoptiondPost = Posts.transformPost(dict: dict!)
//This will look up all users at once
self.fetchUser(userid: newAdoptiondPost.userid!, completed:
tempPost.insert(newAdoptiondPost, at: 0)
DispatchQueue.main.async
self.postsadoption = tempPost
self.postsadoption.sort (p1, p2) -> Bool in
return p1.timeStamp?.compare(p2.timeStamp!) == .orderdDescending
self.adoptionCollectionView.reloadData()
self.refresherAdoption.endRefreshing()
)
With that the posts adoption array will be sorted depending on the timestamp that you have.
that worked perfectly!!!! THANKS A LOT!
– Code With Xime
Nov 21 '18 at 22:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327406%2fposts-being-uploaded-randomly-in-collection-view-swift-firebase%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you already have the posts ordered by post type you can just do sorting depending on the timestamp. For example
@objc func observePostsAdoption()
let postsRef = Database.database().reference().child("posts")
postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value) (snapshot) in
var tempPost = [Posts]()
for child in snapshot.children
if let childSnapshot = child as? DataSnapshot
let dict = childSnapshot.value as? [String: Any]
let newAdoptiondPost = Posts.transformPost(dict: dict!)
//This will look up all users at once
self.fetchUser(userid: newAdoptiondPost.userid!, completed:
tempPost.insert(newAdoptiondPost, at: 0)
DispatchQueue.main.async
self.postsadoption = tempPost
self.postsadoption.sort (p1, p2) -> Bool in
return p1.timeStamp?.compare(p2.timeStamp!) == .orderdDescending
self.adoptionCollectionView.reloadData()
self.refresherAdoption.endRefreshing()
)
With that the posts adoption array will be sorted depending on the timestamp that you have.
that worked perfectly!!!! THANKS A LOT!
– Code With Xime
Nov 21 '18 at 22:29
add a comment |
If you already have the posts ordered by post type you can just do sorting depending on the timestamp. For example
@objc func observePostsAdoption()
let postsRef = Database.database().reference().child("posts")
postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value) (snapshot) in
var tempPost = [Posts]()
for child in snapshot.children
if let childSnapshot = child as? DataSnapshot
let dict = childSnapshot.value as? [String: Any]
let newAdoptiondPost = Posts.transformPost(dict: dict!)
//This will look up all users at once
self.fetchUser(userid: newAdoptiondPost.userid!, completed:
tempPost.insert(newAdoptiondPost, at: 0)
DispatchQueue.main.async
self.postsadoption = tempPost
self.postsadoption.sort (p1, p2) -> Bool in
return p1.timeStamp?.compare(p2.timeStamp!) == .orderdDescending
self.adoptionCollectionView.reloadData()
self.refresherAdoption.endRefreshing()
)
With that the posts adoption array will be sorted depending on the timestamp that you have.
that worked perfectly!!!! THANKS A LOT!
– Code With Xime
Nov 21 '18 at 22:29
add a comment |
If you already have the posts ordered by post type you can just do sorting depending on the timestamp. For example
@objc func observePostsAdoption()
let postsRef = Database.database().reference().child("posts")
postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value) (snapshot) in
var tempPost = [Posts]()
for child in snapshot.children
if let childSnapshot = child as? DataSnapshot
let dict = childSnapshot.value as? [String: Any]
let newAdoptiondPost = Posts.transformPost(dict: dict!)
//This will look up all users at once
self.fetchUser(userid: newAdoptiondPost.userid!, completed:
tempPost.insert(newAdoptiondPost, at: 0)
DispatchQueue.main.async
self.postsadoption = tempPost
self.postsadoption.sort (p1, p2) -> Bool in
return p1.timeStamp?.compare(p2.timeStamp!) == .orderdDescending
self.adoptionCollectionView.reloadData()
self.refresherAdoption.endRefreshing()
)
With that the posts adoption array will be sorted depending on the timestamp that you have.
If you already have the posts ordered by post type you can just do sorting depending on the timestamp. For example
@objc func observePostsAdoption()
let postsRef = Database.database().reference().child("posts")
postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value) (snapshot) in
var tempPost = [Posts]()
for child in snapshot.children
if let childSnapshot = child as? DataSnapshot
let dict = childSnapshot.value as? [String: Any]
let newAdoptiondPost = Posts.transformPost(dict: dict!)
//This will look up all users at once
self.fetchUser(userid: newAdoptiondPost.userid!, completed:
tempPost.insert(newAdoptiondPost, at: 0)
DispatchQueue.main.async
self.postsadoption = tempPost
self.postsadoption.sort (p1, p2) -> Bool in
return p1.timeStamp?.compare(p2.timeStamp!) == .orderdDescending
self.adoptionCollectionView.reloadData()
self.refresherAdoption.endRefreshing()
)
With that the posts adoption array will be sorted depending on the timestamp that you have.
answered Nov 18 '18 at 13:39
Galo Torres SevillaGalo Torres Sevilla
1,0032211
1,0032211
that worked perfectly!!!! THANKS A LOT!
– Code With Xime
Nov 21 '18 at 22:29
add a comment |
that worked perfectly!!!! THANKS A LOT!
– Code With Xime
Nov 21 '18 at 22:29
that worked perfectly!!!! THANKS A LOT!
– Code With Xime
Nov 21 '18 at 22:29
that worked perfectly!!!! THANKS A LOT!
– Code With Xime
Nov 21 '18 at 22:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327406%2fposts-being-uploaded-randomly-in-collection-view-swift-firebase%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If your Post object has a property such as timestamp it will be very easy to do sorting. Can you show your Posts struct?
– Galo Torres Sevilla
Nov 16 '18 at 12:57
Hey Galo! I've added it to the question.
– Code With Xime
Nov 16 '18 at 13:25
Also, the thing is that I need to sort by "postType" for in this case adoption, because I have several other postTypes such as lost and found. Can I sort by the two different types? Timestamp AND postType?
– Code With Xime
Nov 16 '18 at 13:26
What exactly do you mean postType? I don't see any property where the postType is set.
– Galo Torres Sevilla
Nov 16 '18 at 14:15
Check in the first function. The observePostsAdoption. The postType is in Firebase --> let postsRef = Database.database().reference().child("posts") postsRef.queryOrdered(byChild: "postType").queryEqual(toValue: "adopt").observe(.value)
– Code With Xime
Nov 16 '18 at 17:51