Comments (9)
@ludovicoloreti could you post the code that you're using within weekViewGenerateEvents()
?
from swift-week-view.
yes of course! Thank you for your fast reply!
func weekViewGenerateEvents(_ weekView: WeekView, date: DateInRegion) -> [WeekViewEvent] {
let db = dbRef.child("items").child(codiceUtente)
db.observe(.value, with: { (snapshot) in
guard let itemData = snapshot.children.allObjects as? [DataSnapshot] else {return}
if (snapshot.exists() == false) {
Utils.showAlert(title: "Nessun Dato", msg: "Nessun dato presente nel Database di Firebase!", in: self)
return
} else {
for child in itemData {
guard let eventName = child.childSnapshot(forPath: "eventName").value as? String else {
Utils.showAlert(title: "Erroe campo eventName", msg: "Errore nel campo NOME_EVENTO (titolo evento), contattare amministratore!", in: self)
return
}
guard let startDate = child.childSnapshot(forPath: "startDate").value as? String else {
Utils.showAlert(title: "Erroe campo startDate", msg: "Errore nel campo DATA_INIZIO, contattare amministratore!", in: self)
return
}
guard let endDate = child.childSnapshot(forPath: "endDate").value as? String else {
Utils.showAlert(title: "Erroe campo endDate", msg: "Errore nel campo DATA_FINE, contattare amministratore!", in: self)
return
}
let initDate = DateInRegion(string: startDate, format: .custom("dd-MM-yyyy HH:mm"), fromRegion: self.regionRome)!
let finalDate = DateInRegion(string: endDate, format: .custom("dd-MM-yyyy HH:mm"), fromRegion: self.regionRome)!
let item: WeekViewEvent = WeekViewEvent(title: eventName, start: initDate, end: finalDate)
if date.day == initDate.day && date.day == finalDate.day {
self.items.append(item)
}
DispatchQueue.main.async {
print("CIAO",self.items)
// return self.items
}
}
}
})
// print("itemsssss",date.day ,"\n\n\n\n\n\n\n",items,"\n\n\n\n\n\n\n\n end itemszzz")
return items
}
The problem is (maybe the code is also not correct in the end where I want to print the array of items declared in the top of the viewcontrolller
class like this: var items = [WeekViewEvent]()
) my code is fired in different time into the weekViewGenerateEvents()
function...
However the prob
from swift-week-view.
Ok so the problem:
weeViewGenerateEvents
runs synchronously- Firebase code runs asynchronously
This means that weeViewGenerateEvents
has already returned before the firebase code has completed fetching your results. I'm working on a fix right now.
from swift-week-view.
God save @EvanCooper9
Thousands of thanks!
from swift-week-view.
I noticed also that for each event you're creating, you're returning that event. You should create all WeekViewEvents
, store them in an array, and return that array.
I added eventCompletion: @escaping ([WeekViewEvent]) -> Void
to the weekViewGenerateEvents
method. It's not perfect but it will work for you. Once you've put all events for a single day in an array, you can do eventCompletion(events)
to send them to the WeekView
.
from swift-week-view.
So you are saying that I can get my data from firebase inside your weekViewGenerateEvents()
, and instead of the returning statement (you talked before that I've used it, (now obviously wrong)) I can literally append items to an array (like this array outside every functions: var items = [WeekViewEvent]()
), then always inside your function I can compare all the array with your currently date
(the input in your function, type DateInRegion
) and add to something like a new event
array with all the events in that date, and it will redo all of this I just said for every day in the printed WeekView
.
Is it correct?
(and I add that maybe I could put my firebase data get outside that function because the array with events is always the same, but obviously I don't know how because it's async so I'm not able to do something like this, I'm able to do only the first part I told you before this brackets)
from swift-week-view.
@ludovicoloreti You really have two options, so you can do one of the following.
Given that items
is of type [WeekViewEvent]
:
- Fetch all your data from Firebase outside of
weekViewGenerateEvents()
, then return the ones that match withdate
within the function like so:return items
. - Fetch all events that are related to
date
withinweekViewGenerateEvents()
, and use the asynchronous callback to pass these events to theWeekView
like so :eventCompletion(items)
, and thenreturn []
.
from swift-week-view.
Last question:
Is it possible to add events directly without using weekViewGenerateEvents
?
In that way it will be simple because I will add events async and only one time, every event will be added. Sorry and thanks
from swift-week-view.
Hey, is this still an issue? If so, have a look at the newest update
from swift-week-view.
Related Issues (20)
- It is really good . I have an query i have a array in which i have time start and end and as well as description , can you please tell me how to add my data as events in your generate event function .Thank you HOT 7
- No such module 'TimelineCollectionView'
- No such module 'TimelineCollectionView' HOT 2
- drag and drop feature [enhancement] HOT 1
- StartHour Won't Changed
- how to set start date and end date ?
- Swift Week View with JSON HOT 1
- 5.3 compiler does not like TimeLineCollectionView.framework HOT 3
- Support for ALL-Day and multi-day events? HOT 1
- weekViewStylerHeaderView returns optional? HOT 1
- Setting Start and EndHour changes the Event view but not the grid and time label
- Hi I am trying out your project and got an issue HOT 1
- scrolling issue
- How to set the Event for particular time of day HOT 1
- how use weekViewDidClickOnFreeTime
- Creating Events asynchronously HOT 3
- Memory leak HOT 1
- Customize to Half-hour HOT 1
- Scroll view HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-week-view.