How to read data from firebase, block with doesn't work?How to store and view images on firebase?How to call Objective-C code from SwiftHow to detect tableView cell touched or clicked in swiftUpdate or reload UITableView after completion of delete action on detail viewFirebase 2.0 - Reading data from FIRDataSnapshot not workingTableView not displaying text with JSON data from API callHow to read data from firebaseHow to read data from FireBaseSwift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift
Why did Spider-Man take a detour to Dorset?
Do dragons smell of lilacs?
Interviewing with an unmentioned 9 months of sick leave taken during a job
Did Voldemort kill his father before finding out about Horcruxes?
How could an animal "smell" carbon monoxide?
How should one refer to knights (& dames) in academic writing?
Advice for paying off student loans and auto loans now that I have my first 'real' job
What happens if there is no space for entry stamp in the passport for US visa?
Is it ethical for a company to ask its employees to move furniture on a weekend?
How could a medieval fortress manage large groups of migrants and travelers?
How Can I Process Untrusted Data Sources Securely?
Why don't commercial aircraft adopt a slightly more seaplane-like design to allow safer ditching in case of emergency?
Can a Resident Assistant Be Told to Ignore a Lawful Order?
Why isn't aluminium involved in biological processes?
How can I find what program is preventing my Mac from going to sleep?
Is this Android phone Android 9.0 or Android 6.0?
Is this artwork (used in a video game) real?
How can I leave a car for someone if we can't meet in person?
Why alcohol had been selected as fuel for the first American space rockets?
What details should I consider before agreeing for part of my salary to be 'retained' by employer?
Construct, in some manner, a four-dimensional "RegionPlot"
How to ask my office to remove the pride decorations without appearing anti-LGBTQ?
What impact would a dragon the size of Asia have on the environment?
If I stood next to a piece of metal heated to a million degrees, but in a perfect vacuum, would I feel hot?
How to read data from firebase, block with doesn't work?
How to store and view images on firebase?How to call Objective-C code from SwiftHow to detect tableView cell touched or clicked in swiftUpdate or reload UITableView after completion of delete action on detail viewFirebase 2.0 - Reading data from FIRDataSnapshot not workingTableView not displaying text with JSON data from API callHow to read data from firebaseHow to read data from FireBaseSwift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I try to read data from firebase. I've made observeSingleEvent, but block "with" not works, why?
I try to debug and I notice that block with doesn't work.
userID has correct ID
and reference also correct
var ref: DatabaseReference!
var snapData: NSDictionary?
var nameString = [String]()
override func viewDidLoad()
super.viewDidLoad()
ref = Database.database().reference()
loadData()
table.delegate = self
table.dataSource = self
table.register(UITableViewCell.self, forCellReuseIdentifier: "indentifire")
view.addSubview(table)
// Do any additional setup after loading the view.
// ---------------------------------------------------
//loading data from FireBase
func loadData()
let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
self.snapData = snapshot.value as? NSDictionary
)
// delegate
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
var temp = 0
for (_,val) in snapData!
if val as? String == "false"
temp += 1
nameString.append(val as! String)
return temp
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let cell = table.dequeueReusableCell(withIdentifier: "indentifire", for: indexPath)
cell.textLabel!.text = nameString[indexPath.row]
return cell
```
this is my database
![photo](https://imgur.com/a/0UzOPJ7
swift firebase firebase-realtime-database
add a comment |
I try to read data from firebase. I've made observeSingleEvent, but block "with" not works, why?
I try to debug and I notice that block with doesn't work.
userID has correct ID
and reference also correct
var ref: DatabaseReference!
var snapData: NSDictionary?
var nameString = [String]()
override func viewDidLoad()
super.viewDidLoad()
ref = Database.database().reference()
loadData()
table.delegate = self
table.dataSource = self
table.register(UITableViewCell.self, forCellReuseIdentifier: "indentifire")
view.addSubview(table)
// Do any additional setup after loading the view.
// ---------------------------------------------------
//loading data from FireBase
func loadData()
let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
self.snapData = snapshot.value as? NSDictionary
)
// delegate
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
var temp = 0
for (_,val) in snapData!
if val as? String == "false"
temp += 1
nameString.append(val as! String)
return temp
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let cell = table.dequeueReusableCell(withIdentifier: "indentifire", for: indexPath)
cell.textLabel!.text = nameString[indexPath.row]
return cell
```
this is my database
![photo](https://imgur.com/a/0UzOPJ7
swift firebase firebase-realtime-database
add a comment |
I try to read data from firebase. I've made observeSingleEvent, but block "with" not works, why?
I try to debug and I notice that block with doesn't work.
userID has correct ID
and reference also correct
var ref: DatabaseReference!
var snapData: NSDictionary?
var nameString = [String]()
override func viewDidLoad()
super.viewDidLoad()
ref = Database.database().reference()
loadData()
table.delegate = self
table.dataSource = self
table.register(UITableViewCell.self, forCellReuseIdentifier: "indentifire")
view.addSubview(table)
// Do any additional setup after loading the view.
// ---------------------------------------------------
//loading data from FireBase
func loadData()
let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
self.snapData = snapshot.value as? NSDictionary
)
// delegate
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
var temp = 0
for (_,val) in snapData!
if val as? String == "false"
temp += 1
nameString.append(val as! String)
return temp
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let cell = table.dequeueReusableCell(withIdentifier: "indentifire", for: indexPath)
cell.textLabel!.text = nameString[indexPath.row]
return cell
```
this is my database
![photo](https://imgur.com/a/0UzOPJ7
swift firebase firebase-realtime-database
I try to read data from firebase. I've made observeSingleEvent, but block "with" not works, why?
I try to debug and I notice that block with doesn't work.
userID has correct ID
and reference also correct
var ref: DatabaseReference!
var snapData: NSDictionary?
var nameString = [String]()
override func viewDidLoad()
super.viewDidLoad()
ref = Database.database().reference()
loadData()
table.delegate = self
table.dataSource = self
table.register(UITableViewCell.self, forCellReuseIdentifier: "indentifire")
view.addSubview(table)
// Do any additional setup after loading the view.
// ---------------------------------------------------
//loading data from FireBase
func loadData()
let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
self.snapData = snapshot.value as? NSDictionary
)
// delegate
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
var temp = 0
for (_,val) in snapData!
if val as? String == "false"
temp += 1
nameString.append(val as! String)
return temp
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let cell = table.dequeueReusableCell(withIdentifier: "indentifire", for: indexPath)
cell.textLabel!.text = nameString[indexPath.row]
return cell
```
this is my database
![photo](https://imgur.com/a/0UzOPJ7
swift firebase firebase-realtime-database
swift firebase firebase-realtime-database
edited Mar 26 at 15:59
jeff porter
3,84811 gold badges53 silver badges105 bronze badges
3,84811 gold badges53 silver badges105 bronze badges
asked Mar 26 at 8:06
Игорь СорокинИгорь Сорокин
224 bronze badges
224 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The database operations work asynchronously. Map the data in loadData
and reload the table view
func loadData()
let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
if let snapData = snapshot.value as? [String:Any]
self.nameString = snapData.values.compactMap $0 as? String
DispatchQueue.main.async
self.table.reloadData()
)
And in numberOfRowsInSection
just return the number of items in nameString
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return nameString.count
it works, Thank you!
– Игорь Сорокин
Mar 26 at 8:32
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%2f55352389%2fhow-to-read-data-from-firebase-block-with-doesnt-work%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
The database operations work asynchronously. Map the data in loadData
and reload the table view
func loadData()
let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
if let snapData = snapshot.value as? [String:Any]
self.nameString = snapData.values.compactMap $0 as? String
DispatchQueue.main.async
self.table.reloadData()
)
And in numberOfRowsInSection
just return the number of items in nameString
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return nameString.count
it works, Thank you!
– Игорь Сорокин
Mar 26 at 8:32
add a comment |
The database operations work asynchronously. Map the data in loadData
and reload the table view
func loadData()
let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
if let snapData = snapshot.value as? [String:Any]
self.nameString = snapData.values.compactMap $0 as? String
DispatchQueue.main.async
self.table.reloadData()
)
And in numberOfRowsInSection
just return the number of items in nameString
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return nameString.count
it works, Thank you!
– Игорь Сорокин
Mar 26 at 8:32
add a comment |
The database operations work asynchronously. Map the data in loadData
and reload the table view
func loadData()
let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
if let snapData = snapshot.value as? [String:Any]
self.nameString = snapData.values.compactMap $0 as? String
DispatchQueue.main.async
self.table.reloadData()
)
And in numberOfRowsInSection
just return the number of items in nameString
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return nameString.count
The database operations work asynchronously. Map the data in loadData
and reload the table view
func loadData()
let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
if let snapData = snapshot.value as? [String:Any]
self.nameString = snapData.values.compactMap $0 as? String
DispatchQueue.main.async
self.table.reloadData()
)
And in numberOfRowsInSection
just return the number of items in nameString
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return nameString.count
answered Mar 26 at 8:15
vadianvadian
167k19 gold badges185 silver badges206 bronze badges
167k19 gold badges185 silver badges206 bronze badges
it works, Thank you!
– Игорь Сорокин
Mar 26 at 8:32
add a comment |
it works, Thank you!
– Игорь Сорокин
Mar 26 at 8:32
it works, Thank you!
– Игорь Сорокин
Mar 26 at 8:32
it works, Thank you!
– Игорь Сорокин
Mar 26 at 8:32
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55352389%2fhow-to-read-data-from-firebase-block-with-doesnt-work%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