Skip to content

Commit

Permalink
Added synchronous version to visibleDates function
Browse files Browse the repository at this point in the history
  • Loading branch information
patchthecode committed Oct 23, 2016
1 parent 3eca0fd commit ff34617
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Sources/UserInteractionFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,23 @@ extension JTAppleCalendarView {
/// Returns the visible dates of the calendar.
/// - returns:
/// - DateSegmentInfo
public func visibleDates(_ completionHandler: @escaping (_ dateSegmentInfo: DateSegmentInfo) ->()) {
public func visibleDates()-> DateSegmentInfo {
let emptySegment = DateSegmentInfo(indates: [], monthDates: [], outdates: [])

if !calendarIsAlreadyLoaded {
delayedExecutionClosure.append {
self.visibleDates(completionHandler)
}
return
return emptySegment
}

let rect = CGRect(x: calendarView.contentOffset.x + 1, y: calendarView.contentOffset.y + 1, width: calendarView.frame.width - 2, height: calendarView.frame.height - 2)
guard let attributes = calendarViewLayout.layoutAttributesForElements(in: rect), attributes.count > 0 else {
return
return emptySegment
}

let indexPaths: [IndexPath] = Array(Set(attributes.map { $0.indexPath })).sorted()

var inDates = [Date]()
var monthDates = [Date]()
var outDates = [Date]()

for indexPath in indexPaths {
let info = dateInfoFromPath(indexPath)

Expand All @@ -94,6 +92,17 @@ extension JTAppleCalendarView {
}

let retval = DateSegmentInfo(indates: inDates, monthDates: monthDates, outdates: outDates)
return retval
}

public func visibleDates(_ completionHandler: @escaping (_ dateSegmentInfo: DateSegmentInfo) ->()) {
if !calendarIsAlreadyLoaded {
delayedExecutionClosure.append {
self.visibleDates(completionHandler)
}
return
}
let retval = visibleDates()
completionHandler(retval)
}

Expand Down

0 comments on commit ff34617

Please sign in to comment.