I have an array of dates (that user previously tapped) and I'm trying display them on a calendar by assigning them isSelected = true, but I can't because Xcode tells me isSelected is a let.
Is there some workaround to this?
Acknowledged your problem. Will give you a response in some hours.
@antonijap Ok. As i'm the sole dev on this project, I missed this obvious feature. Thanks for pointing it out to me. I now have the code for this updated and i'm now reviewing it before i commit it. Was there any other part of this project you found to be missing? It's always good to have more eyes.
For now, this is the only thing that was missing. If I find anything else I'll let you know. Thanks for being so quick with this issue.
Description of the fix: -->
func selectDate(date: NSDate) will be changed to func selectDate(date: [NSDate])
In that function, you can provide an array of dates to be selected.
So let's say you have a bunch of dates saved from some time before. You can use like this:
let d1 = someDate...
let d2 = someDate...
let d3 = someDate...
calendarView.selectDate([d1, d2, d3])
This will cause your dates to be selected. If your date is off the screen, it will still be selected. Does this proposed fix sound like it will meet your needs?
I think it will be great. Let me show you my code:
func setupCellBeforeDisplay(cellState: CellState, date: NSDate) {
// Setup Cell text
dayLabel.text = cellState.text
// Setup text color
configureTextColor(cellState)
// Setup Cell Background color for today
if c.stringFromDate(date) == todayDate {
todayView.hidden = false
todayView.layer.cornerRadius = 10
} else {
todayView.hidden = true
}
// Setup cell selection status
configueViewIntoBubbleView(cellState)
// Configure Visibility
configureVisibility(cellState)
// Grab selected dates from database, select it
for day in demoDays {
let blah = c.dateFromString(day)
if date.isEqualToDate(blah!) {
dayLabel.text = "YES" // Just for testing, delete this
// make them selectable
}
}
}
Basically, when a user taps on certain dates they will be stored in my database, and then they should be permanently displayed as selected dates on a calendar. User can deselect it and they will be erased from a database. Can you just explain a bit how should I use updated function with my code?
The function isnt updated yet. I have not pushed the changes yet. I am currently testing it to make sure i didnt break anything :) . But I will be pushing it in some hours.
Now in regards to how you will use it, here are some things.
1) I see you're using the demo code provided. I see you have the following code _inside_ of the setupCellBeforeDisplay function.
// Grab selected dates from database, select it
for day in demoDays {
let blah = c.dateFromString(day)
if date.isEqualToDate(blah!) {
dayLabel.text = "YES" // Just for testing, delete this
// make them selectable
}
}
Keep in mind the calendarView is just like a UITableView. Just like in a UITableView, the cellForRowAtIndexPath will be called for _every_ cell, it will be the same for this calendarView. Therefore the setupCellBeforeDisplay function will be called before every cell is displayed. The function is meant to give you some time to setup the dayCell's visual looks before it is displayed. Are you sure you want to put a loop in that function that takes information from a database? Remember, setting up a cell should be fast.
2) I would set this up in your viewController. After i push the code change, you will be able to use the new function like this
// Grab selected dates from database, select it
for day in demoDays {
let blah = c.dateFromString(day)
if date.isEqualToDate(blah!) {
dayLabel.text = "YES" // Just for testing, delete this
// make them selectable
calendarView.selectDate([blah])
}
}
or you can gather them to be selected all at once. Like so:
// Grab selected dates from database, select it
var datesToBeSelected: [NSDate] = []
for day in demoDays {
let blah = c.dateFromString(day)
if date.isEqualToDate(blah!) {
dayLabel.text = "YES" // Just for testing, delete this
// make them selectable
datesToBeSelected.append(blah)
}
}
calendarView.selectDate(datesToBeSelected)
I played with "old" function selectDate(NSDate), I will use it in viewDidLoad and it should work great. I was playing in setupCellBeforeDisplay because selectDate function only accepted one value. I won't use my code, this new function should do the trick.
Alright then. I will still do the update however. The selecting of the date with the _old_ function will only work if the date is visible on the screen. You will have to scroll to the date first before selecting it. Like so:
calendarView.scrollToDate(someDate)
calendarView.selectDate(someDate)
After the new code is updated however, selecting a date will work even if the date is not visible on screen. Will update code in some some hours. Cheers.
Code committed. You can check it out now. It is now version 2.0.0 (so you can put that in your Pod file if you are using cocoapods)
I decided to let the function have the same name. If you need multiple dates selected, then simply select them in a loop. I will close this issue now, but if there is still some error with it, then do not hesitate to reopen it. Thanks.

Shouldn't it be like you said calendarView.selectDate([d1, d2, d3])Now it's not a method.
Ok. As i've said in the last message. I have decided to leave the function with the same name. Therefore, to use do just like you have done.
self.calendarView.selectDate(date)
If you need to select multiple dates, you can select this like so:
for date in dates {
self.calendar.selectDate(date)
}
I did not want to break the functionality of method by changing its signature to accept an array or dates.
Tomorrow, i will also commit a new function called:
func selectDate(date: [NSDate])
This one will behave the way like we have discussed. But for now, use the function in a loop like I showed you above.
Oh sorry, I didn't gather that part. Well, untill tomorrow...
Committed. Do update on version 2.0.1.
Let me know if it works for you.
Ok, I tested it, it works. Thanks!
Hey, im seeing this message in my email -> "I don't know if it's something in my code but didSelectDate is not working as expected. When I click nothing happens, if I scroll forward and then get back to month where selected date is - then it shows."
But im not seeing this message here. Are you experiencing difficulty? or was that an old email.
I deleted it because I found a way to make everything work. I attached delegate and datasource on my view controller and it didn't work right, then I made extension and now it works.
I think i know why it wasnt working for you. I suspect you didnt look at the release notes for 2.0.1.
this method was changed from this:
func calendar(calendar: JTAppleCalendarView, didSelectDate date: NSDate, cell: JTAppleDayCellView, cellState: CellState)
to this
func calendar(calendar: JTAppleCalendarView, didSelectDate date: NSDate, cell: JTAppleDayCellView?, cellState: CellState)
Notice there is an added --> ? after the JTAppleDayCellView. This is the only major change made in 2.0.0 that can break functionality.
Just to let you know selectDates is not working well with Firebase. I have reading data and displaying it on a calendar in my viewDidLoad. I'm using observeEventType so every change in Firebase triggers reading/displaying data.
So, in my Firebase block of code I have selectDates(array of nsdates) and in didSelectDate I'm uploading selected dates into Firebase which triggers observeEventType which has selectDates(array of nsdates) which triggers didSelectDate... These 2 methods are playing ping-pong and I wonder is there some way not to trigger didSelectDate when using selectDates(array of nsdates) method somewhere in my code?
To show you problem in a simple form, this is a code that happens when the app loads:
ref.childByAppendingPath("dates").queryOrderedByValue().observeSingleEventOfType(.Value, withBlock: { snapshot in
self.selectedDays = []
if let dates = snapshot.value as? String {
let days = dates.componentsSeparatedByString(", ")
for day in days {
let date = day.toDate(DateFormat.Custom("YYYY MM dd"))!
self.selectedDays.append(date)
}
}
print("I've just downloaded: \(self.selectedDays)")
self.calendarView.selectDates(self.selectedDays)
}, withCancelBlock: { error in
print(error.description)
})
And this is a code in didSelectDate:
func calendar(calendar: JTAppleCalendarView, didSelectDate date: NSDate, cell: JTAppleDayCellView?, cellState: CellState) {
(cell as? CellView)?.cellSelectionChanged(cellState)
print("I just tapped with my finger: \(date.toString(DateFormat.Custom("YYYY MM dd"))!)")
}
AND when I open my app, without touching anything, console says:
I've just downloaded: [2016-04-10 22:00:00 +0000, 2016-04-11 22:00:00 +0000]
I just tapped with my finger: 2016 04 11
I just tapped with my finger: 2016 04 12
Maybe you intended to connect these two functions but it is impossible to work with multiple dates in a database when selectDates(dates: [NSDate]) fires up didSelectDate which should trigger only when a user taps on it.
So just to be clear, you want to select a date, but you only want the didSelectDate to be triggered only when a user taps on it, and not when youre just trying to setup the initial data?
Yes, if it's possible. Because when I load initial data .selectDates() triggers didSelectDate which has code that uploads to database which again calls .selectDates and then I have a nasty loop.
As this is a new issue i've created a new Issue here -> https://github.com/patchthecode/JTAppleCalendar/issues/4
Expect a fix in some hours.
You're really quick. As you are better programmer than me I can't offer you help with that but if you want super-cool logo for your calendar or something like that - I'm here.
Ah cool. Well, i'm not much of a designer, so i just whipped one up before creating this app. Since i'm already so attached to the one i created, it will be sad to part with it. But i wont refuse a logo if you create one that looks awesome. But no pressure. It's up to you :)
Hello,
I am not getting selected date just like today date is 2017-10-14 but i am getting previous date
currentDate 2017-10-14 10:59:02 +0000 selectedDate 2017-10-12 18:30:00 +0000
I tap on 2017-10-13 but i get 2017-10-12
what should i have to do.
@tosifkanuga
let me know if this discussion helped -> https://github.com/patchthecode/JTAppleCalendar/issues/252
My problem is solve
On 14 Oct 2017 9:05 p.m., "JTAppleCalendar" notifications@github.com
wrote:
@tosifkanuga https://github.com/tosifkanuga
let me know if this discussion helped -> #252
https://github.com/patchthecode/JTAppleCalendar/issues/252—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/patchthecode/JTAppleCalendar/issues/1#issuecomment-336642799,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AUQUTjb3wROIzSx-4aE_zwQPLELhhLTHks5ssNTJgaJpZM4IAeRP
.
awesome :)
cool 🍻
Thank you for your response ☺️👍
On 14 Oct 2017 9:08 p.m., "JTAppleCalendar" notifications@github.com
wrote:
awesome :)
cool 🍻—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/patchthecode/JTAppleCalendar/issues/1#issuecomment-336643033,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AUQUTvjqk6YRAEDti9uyyne3j27wuqo4ks5ssNWEgaJpZM4IAeRP
.
hey.. I want select dates when calendar is load ...n I used selectdates() bt last date will be selected ...I used for loop then all dates are selected....but problem is when I scrolled then all selected dates are gone
@axita27 what code did you use to select the dates?
func setupViewsOfCalendar(from visibleDates: DateSegmentInfo){
guard let date = visibleDates.monthDates.first?.date else {return}
Formatter.dateFormat = "MMM yyyy"
self.MonthLbl.text = Formatter.string(from: date)
for i in self.arr{
self.calendarView.selectDates([i])
}
self.ShowDateTime?.text = ""
}
this function is called in didScrollToDateSegmentWith method
after 5-6 time scrolled when one of the date is unselected
that is not how to select multiple dates.
This is how it is done
self.calendarView.selectDates(self.arr)
@axita27 I do not understand what you area asking.
ohhh....I just want to select my array dates....n not select other dates...
and when I scrolled multiple time current month to other month then one of my array date unselected automatically
ohhh....I just want to select my array dates....
calendarView.allowsMultipleSelection = true
self.calendarView.selectDates(self.arr)
and when I scrolled multiple time current month to other month then one of my array date unselected automatically
Is this something you want? or is this something you do not want?
yes I don't want when I scrolled multiple time current month to other month then one of my array date unselected automatically
and also this: not select other dates.
@axita27 can you join me here? https://gitter.im/patchthecode/JTAppleCalendar
yes