ios - Open Firebase Database Feed -


does have suggestion how rid off user obligation when posting new element firebase database? create open feed 1 particular user. thank you!

the function starts like:

   func fetchposts(){      let ref = database.database().reference()     ref.child("users").queryorderedbykey().observesingleevent(of: .value, with: { snapshot inlet users = snapshot.value as! [string : anyobject] 

the main problem see in this:

        (_,value) in users {             if let uid = value["uid"] as? string {                 if uid == auth.auth().currentuser?.uid {                     if let followingusers = value["following"] as? [string : string]{                         (_,user) in followingusers{                             self.following.append(user)                         }                     }                     self.following.append(auth.auth().currentuser!.uid)                      ref.child("posts").queryorderedbykey().observesingleevent(of: .value, with: { (snap) in                           let postssnap = snap.value as! [string : anyobject]                          (_,post) in postssnap {                             if let userid = post["userid"] as? string {                                 each in self.following {                                     if each == userid { 

i guess same:

                                        let posst = post()                                         if let author = post["author"] as? string, let likes = post["likes"] as? int, let pathtoimage = post["pathtoimage"] as? string, let postid = post["postid"] as? string {                                              posst.author = author                                             posst.likes = likes                                             posst.pathtoimage = pathtoimage                                             posst.postid = postid                                             posst.userid = userid                                             if let people = post["peoplewholike"] as? [string : anyobject] {                                                 (_,person) in people {                                                     posst.peoplewholike.append(person as! string)                                                 }                                             }                                              self.posts.append(posst)                                         }                                     }                                 }                                  self.collectionview.reloaddata()                             }                         }                     })                 }             }         }      })} 

ok if understanding question correctly want signed in able see posts not posts of users following.

if in fact case not need check user following. want load of posts. change

for (_,post) in postssnap {      if let userid = post["userid"] as? string {           each in self.following {                if each == userid { 

to

  self.ref.child("posts").queryorderedbykey().observesingleevent(of: .value, with: { snap in                         if let postssnap = snap.value as? [string: anyobject] {                             for(_, post) in postssnap {                                 if let userid = post["userid"] as? string {                                     each in self.following {                                         if each == userid {                                             let posst = post()                                              if let author = post["author"] as? string, let likes = post["likes"] as? int, let pathtoimage = post["pathtoimage"] as? string, let postid = post["postid"] as? string, let postdescription = post["postdescription"] as? string, let timestamp = post["timestamp"] as? double, let category = post["category"] as? string, let group = post["group"] as? int {                                                  posst.author = author                                                 posst.likes = likes                                                 posst.pathtoimage = pathtoimage                                                 posst.postid = postid                                                 posst.userid = userid                                                 posst.fancypostdescription = self.createattributedstring(author: author, posttext: postdescription)                                                 posst.postdescription = author + ": " + postdescription                                                 posst.timestamp = timestamp                                                 posst.group = group                                                 posst.category = category                                                 posst.userwhopostedlabel = self.createattributedpostlabel(username: author, table: group, category: category)                                                  if let people = post["peoplewholike"] as? [string: anyobject] {                                                     for(_, person) in people {                                                         posst.peoplewholike.append(person as! string)                                                     }                                                 }                                                 self.posts.append(posst)                                             } // end if let                                         }                                     }                                     self.tableview.reloaddata()                                 }                             }                         }                     })                     ref.removeallobservers() 

if want able read / write database have update rules in firebase console. clicking on database rules. default rules this:

{   "rules": {     ".read": "auth != null",     ".write": "auth != null"   } } 

change them to

{   "rules": {     ".read": "true",     ".write": "true"   } } 

i looked @ video you're following , make's lot of mistakes. when request data firebase should paging i.e. loading set number of posts , loading more based on scroll position.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -