Read and use dates from Firebase in tableView
In my Firebase I have a timestamp
that I want to read out and populate in a tableView
The Firebase structure looks like this:
"OpeHS4UhH6YWcK4aPHJWumueCQP2" : {
"Events" : {
"Date" : {
"-LQYDWAKlzTrlTtO1Qiz" : 1541410526186,
"-LQYspEghK3KE27MlFNE" : 1541421618601,
"-LQsILjpNqKwLl9XBcQm" : 1541764115618,
"-LQsYbhf-vl-NnRLTHhK" : 1541768379422
},
So I want to go down the childByAutoID/Events/Date
and read out all dates and display in a `tableView.
The closest I have gotten is something like this:
var eventDates = [String]()
func getEventHistory() {
let eventHistoryRef = Database.database().reference().child("users/(uid)/Events/")
eventHistoryRef.observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? NSDictionary
if let eventDate = value?["Date"] as? [String:String] {
self.DateHistoryArray += Array(eventDate.values)
}
self.tableView.reloadData()
// ...
}) { (error) in
print(error.localizedDescription)
}
}
Im not able to convert the dates and add them to the array.
swift firebase uitableview
add a comment |
In my Firebase I have a timestamp
that I want to read out and populate in a tableView
The Firebase structure looks like this:
"OpeHS4UhH6YWcK4aPHJWumueCQP2" : {
"Events" : {
"Date" : {
"-LQYDWAKlzTrlTtO1Qiz" : 1541410526186,
"-LQYspEghK3KE27MlFNE" : 1541421618601,
"-LQsILjpNqKwLl9XBcQm" : 1541764115618,
"-LQsYbhf-vl-NnRLTHhK" : 1541768379422
},
So I want to go down the childByAutoID/Events/Date
and read out all dates and display in a `tableView.
The closest I have gotten is something like this:
var eventDates = [String]()
func getEventHistory() {
let eventHistoryRef = Database.database().reference().child("users/(uid)/Events/")
eventHistoryRef.observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? NSDictionary
if let eventDate = value?["Date"] as? [String:String] {
self.DateHistoryArray += Array(eventDate.values)
}
self.tableView.reloadData()
// ...
}) { (error) in
print(error.localizedDescription)
}
}
Im not able to convert the dates and add them to the array.
swift firebase uitableview
Are you using an auto ID or a user ID as the top key? It's unclear in the question.
– Jen Person
Nov 13 '18 at 20:50
don't know which array you use to fill the table DateHistoryArray or eventDates ? make sure that you fill the correct one
– Sh_Khan
Nov 13 '18 at 20:57
always track code with breakpoints or logs
– Sh_Khan
Nov 13 '18 at 21:01
@JenPerson Sorry for being imprecise. The correct path is users/uid/Events/Date/chidlByAutoID : dateInMilleseconds
– PerNil
Nov 14 '18 at 20:50
add a comment |
In my Firebase I have a timestamp
that I want to read out and populate in a tableView
The Firebase structure looks like this:
"OpeHS4UhH6YWcK4aPHJWumueCQP2" : {
"Events" : {
"Date" : {
"-LQYDWAKlzTrlTtO1Qiz" : 1541410526186,
"-LQYspEghK3KE27MlFNE" : 1541421618601,
"-LQsILjpNqKwLl9XBcQm" : 1541764115618,
"-LQsYbhf-vl-NnRLTHhK" : 1541768379422
},
So I want to go down the childByAutoID/Events/Date
and read out all dates and display in a `tableView.
The closest I have gotten is something like this:
var eventDates = [String]()
func getEventHistory() {
let eventHistoryRef = Database.database().reference().child("users/(uid)/Events/")
eventHistoryRef.observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? NSDictionary
if let eventDate = value?["Date"] as? [String:String] {
self.DateHistoryArray += Array(eventDate.values)
}
self.tableView.reloadData()
// ...
}) { (error) in
print(error.localizedDescription)
}
}
Im not able to convert the dates and add them to the array.
swift firebase uitableview
In my Firebase I have a timestamp
that I want to read out and populate in a tableView
The Firebase structure looks like this:
"OpeHS4UhH6YWcK4aPHJWumueCQP2" : {
"Events" : {
"Date" : {
"-LQYDWAKlzTrlTtO1Qiz" : 1541410526186,
"-LQYspEghK3KE27MlFNE" : 1541421618601,
"-LQsILjpNqKwLl9XBcQm" : 1541764115618,
"-LQsYbhf-vl-NnRLTHhK" : 1541768379422
},
So I want to go down the childByAutoID/Events/Date
and read out all dates and display in a `tableView.
The closest I have gotten is something like this:
var eventDates = [String]()
func getEventHistory() {
let eventHistoryRef = Database.database().reference().child("users/(uid)/Events/")
eventHistoryRef.observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? NSDictionary
if let eventDate = value?["Date"] as? [String:String] {
self.DateHistoryArray += Array(eventDate.values)
}
self.tableView.reloadData()
// ...
}) { (error) in
print(error.localizedDescription)
}
}
Im not able to convert the dates and add them to the array.
swift firebase uitableview
swift firebase uitableview
asked Nov 13 '18 at 20:40
PerNilPerNil
336
336
Are you using an auto ID or a user ID as the top key? It's unclear in the question.
– Jen Person
Nov 13 '18 at 20:50
don't know which array you use to fill the table DateHistoryArray or eventDates ? make sure that you fill the correct one
– Sh_Khan
Nov 13 '18 at 20:57
always track code with breakpoints or logs
– Sh_Khan
Nov 13 '18 at 21:01
@JenPerson Sorry for being imprecise. The correct path is users/uid/Events/Date/chidlByAutoID : dateInMilleseconds
– PerNil
Nov 14 '18 at 20:50
add a comment |
Are you using an auto ID or a user ID as the top key? It's unclear in the question.
– Jen Person
Nov 13 '18 at 20:50
don't know which array you use to fill the table DateHistoryArray or eventDates ? make sure that you fill the correct one
– Sh_Khan
Nov 13 '18 at 20:57
always track code with breakpoints or logs
– Sh_Khan
Nov 13 '18 at 21:01
@JenPerson Sorry for being imprecise. The correct path is users/uid/Events/Date/chidlByAutoID : dateInMilleseconds
– PerNil
Nov 14 '18 at 20:50
Are you using an auto ID or a user ID as the top key? It's unclear in the question.
– Jen Person
Nov 13 '18 at 20:50
Are you using an auto ID or a user ID as the top key? It's unclear in the question.
– Jen Person
Nov 13 '18 at 20:50
don't know which array you use to fill the table DateHistoryArray or eventDates ? make sure that you fill the correct one
– Sh_Khan
Nov 13 '18 at 20:57
don't know which array you use to fill the table DateHistoryArray or eventDates ? make sure that you fill the correct one
– Sh_Khan
Nov 13 '18 at 20:57
always track code with breakpoints or logs
– Sh_Khan
Nov 13 '18 at 21:01
always track code with breakpoints or logs
– Sh_Khan
Nov 13 '18 at 21:01
@JenPerson Sorry for being imprecise. The correct path is users/uid/Events/Date/chidlByAutoID : dateInMilleseconds
– PerNil
Nov 14 '18 at 20:50
@JenPerson Sorry for being imprecise. The correct path is users/uid/Events/Date/chidlByAutoID : dateInMilleseconds
– PerNil
Nov 14 '18 at 20:50
add a comment |
0
active
oldest
votes
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%2f53289172%2fread-and-use-dates-from-firebase-in-tableview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53289172%2fread-and-use-dates-from-firebase-in-tableview%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
Are you using an auto ID or a user ID as the top key? It's unclear in the question.
– Jen Person
Nov 13 '18 at 20:50
don't know which array you use to fill the table DateHistoryArray or eventDates ? make sure that you fill the correct one
– Sh_Khan
Nov 13 '18 at 20:57
always track code with breakpoints or logs
– Sh_Khan
Nov 13 '18 at 21:01
@JenPerson Sorry for being imprecise. The correct path is users/uid/Events/Date/chidlByAutoID : dateInMilleseconds
– PerNil
Nov 14 '18 at 20:50