Skip to content

Commit

Permalink
swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
FranzBusch committed Sep 24, 2018
1 parent d7b5b5e commit 50e237b
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 28 deletions.
6 changes: 2 additions & 4 deletions JTAppleCalendar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -1111,8 +1110,7 @@
PRODUCT_NAME = JTAppleCalendar;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Sources/JTAppleCalendarDelegateProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protocol JTAppleCalendarDelegateProtocol: class {
var minimumLineSpacing: CGFloat {get set}
var monthInfo: [Month] {get set}
var monthMap: [Int: Int] {get set}
var scrollDirection: UICollectionViewScrollDirection! {get set}
var scrollDirection: UICollectionView.ScrollDirection! {get set}
var sectionInset: UIEdgeInsets {get set}
var totalDays: Int {get}
// Functions
Expand Down
8 changes: 4 additions & 4 deletions Sources/JTAppleCalendarLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class JTAppleCalendarLayout: UICollectionViewLayout, JTAppleCalendarLayoutProtoc

var cellSize: CGSize = CGSize.zero
var itemSizeWasSet: Bool = false
var scrollDirection: UICollectionViewScrollDirection = .horizontal
var scrollDirection: UICollectionView.ScrollDirection = .horizontal
var maxMissCount: Int = 0
var cellCache: [Int: [(Int, Int, CGFloat, CGFloat, CGFloat, CGFloat)]] = [:]
var headerCache: [Int: (Int, Int, CGFloat, CGFloat, CGFloat, CGFloat)] = [:]
Expand Down Expand Up @@ -342,7 +342,7 @@ class JTAppleCalendarLayout: UICollectionViewLayout, JTAppleCalendarLayoutProtoc
let data = headerCache[sectionIndex]!

if CGRect(x: data.2, y: data.3, width: data.4, height: data.5).intersects(rect) {
let attrib = layoutAttributesForSupplementaryView(ofKind: UICollectionElementKindSectionHeader, at: IndexPath(item: data.0, section: data.1))
let attrib = layoutAttributesForSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, at: IndexPath(item: data.0, section: data.1))
attributes.append(attrib!)
}
}
Expand Down Expand Up @@ -659,7 +659,7 @@ class JTAppleCalendarLayout: UICollectionViewLayout, JTAppleCalendarLayoutProtoc
return []
}
if excludeHeaders == true {
return attributes.filter { $0.representedElementKind != UICollectionElementKindSectionHeader }
return attributes.filter { $0.representedElementKind != UICollectionView.elementKindSectionHeader }
}
return attributes
}
Expand All @@ -675,7 +675,7 @@ class JTAppleCalendarLayout: UICollectionViewLayout, JTAppleCalendarLayoutProtoc
if let focusIndexPath = focusIndexPath {
if thereAreHeaders {
let headerIndexPath = IndexPath(item: 0, section: focusIndexPath.section)
if let headerAttr = layoutAttributesForSupplementaryView(ofKind: UICollectionElementKindSectionHeader, at: headerIndexPath) {
if let headerAttr = layoutAttributesForSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, at: headerIndexPath) {
retval = scrollDirection == .horizontal ? CGPoint(x: headerAttr.frame.origin.x, y: 0) : CGPoint(x: 0, y: headerAttr.frame.origin.y)
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/JTAppleCalendarLayoutProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protocol JTAppleCalendarLayoutProtocol: class {
var minimumInteritemSpacing: CGFloat {get set}
var minimumLineSpacing: CGFloat {get set}
var sectionInset: UIEdgeInsets {get set}
var scrollDirection: UICollectionViewScrollDirection {get set}
var scrollDirection: UICollectionView.ScrollDirection {get set}
func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint
func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?
}
Expand Down
22 changes: 11 additions & 11 deletions Sources/JTAppleCalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ open class JTAppleCalendarView: UICollectionView {
}

/// The scroll direction of the sections in JTAppleCalendar.
open var scrollDirection: UICollectionViewScrollDirection!
open var scrollDirection: UICollectionView.ScrollDirection!

/// Enables/Disables the stretching of date cells. When enabled cells will stretch to fit the width of a month in case of a <= 5 row month.
open var allowsDateCellStretching = true
Expand Down Expand Up @@ -147,7 +147,7 @@ open class JTAppleCalendarView: UICollectionView {

if calendarViewLayout.thereAreHeaders && scrollDirection == .vertical {
let indexPath = IndexPath(item: 0, section: sectionIndexPath.section)
guard let attributes = calendarViewLayout.layoutAttributesForSupplementaryView(ofKind: UICollectionElementKindSectionHeader, at: indexPath) else { return retval }
guard let attributes = calendarViewLayout.layoutAttributesForSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, at: indexPath) else { return retval }

let maxYCalendarOffset = max(0, self.contentSize.height - self.frame.size.height)
retval = CGPoint(x: attributes.frame.origin.x,y: min(maxYCalendarOffset, attributes.frame.origin.y))
Expand All @@ -166,7 +166,7 @@ open class JTAppleCalendarView: UICollectionView {
return retval
}

open var sectionInset: UIEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
open var sectionInset: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
open var minimumInteritemSpacing: CGFloat = 0
open var minimumLineSpacing: CGFloat = 0

Expand All @@ -185,9 +185,9 @@ open class JTAppleCalendarView: UICollectionView {
open var scrollingMode: ScrollingMode = .stopAtEachCalendarFrameWidth {
didSet {
switch scrollingMode {
case .stopAtEachCalendarFrameWidth: decelerationRate = UIScrollViewDecelerationRateFast
case .stopAtEach, .stopAtEachSection: decelerationRate = UIScrollViewDecelerationRateFast
case .nonStopToSection, .nonStopToCell, .nonStopTo, .none: decelerationRate = UIScrollViewDecelerationRateNormal
case .stopAtEachCalendarFrameWidth: decelerationRate = UIScrollView.DecelerationRate.fast
case .stopAtEach, .stopAtEachSection: decelerationRate = UIScrollView.DecelerationRate.fast
case .nonStopToSection, .nonStopToCell, .nonStopTo, .none: decelerationRate = UIScrollView.DecelerationRate.normal
}
#if os(iOS)
switch scrollingMode {
Expand Down Expand Up @@ -235,7 +235,7 @@ open class JTAppleCalendarView: UICollectionView {

super.dataSource = self
super.delegate = self
decelerationRate = UIScrollViewDecelerationRateFast
decelerationRate = UIScrollView.DecelerationRate.fast

#if os(iOS)
if isPagingEnabled {
Expand All @@ -260,7 +260,7 @@ open class JTAppleCalendarView: UICollectionView {
return retval
}

func scrollTo(indexPath: IndexPath, triggerScrollToDateDelegate: Bool, isAnimationEnabled: Bool, position: UICollectionViewScrollPosition, extraAddedOffset: CGFloat, completionHandler: (() -> Void)?) {
func scrollTo(indexPath: IndexPath, triggerScrollToDateDelegate: Bool, isAnimationEnabled: Bool, position: UICollectionView.ScrollPosition, extraAddedOffset: CGFloat, completionHandler: (() -> Void)?) {
isScrollInProgress = true
if let validCompletionHandler = completionHandler {
self.delayedExecutionClosure.append(validCompletionHandler)
Expand Down Expand Up @@ -358,7 +358,7 @@ open class JTAppleCalendarView: UICollectionView {
completionHandler: (() -> Void)? = nil) {
if !calendarViewLayout.thereAreHeaders { return }
let indexPath = IndexPath(item: 0, section: section)
guard let attributes = calendarViewLayout.layoutAttributesForSupplementaryView(ofKind: UICollectionElementKindSectionHeader, at: indexPath) else { return }
guard let attributes = calendarViewLayout.layoutAttributesForSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, at: indexPath) else { return }

isScrollInProgress = true
if let validHandler = completionHandler { self.delayedExecutionClosure.append(validHandler) }
Expand Down Expand Up @@ -466,7 +466,7 @@ open class JTAppleCalendarView: UICollectionView {
}
func restoreSelectionStateForCellAtIndexPath(_ indexPath: IndexPath) {
if theSelectedIndexPaths.contains(indexPath) {
selectItem(at: indexPath, animated: false, scrollPosition: UICollectionViewScrollPosition() )
selectItem(at: indexPath, animated: false, scrollPosition: UICollectionView.ScrollPosition() )
}
}
}
Expand All @@ -477,7 +477,7 @@ extension JTAppleCalendarView {
indexPath: IndexPath? = nil,
triggerScrollToDateDelegate: Bool = true,
isAnimationEnabled: Bool,
position: UICollectionViewScrollPosition? = .left,
position: UICollectionView.ScrollPosition? = .left,
extraAddedOffset: CGFloat = 0,
completionHandler: (() -> Void)?) {

Expand Down
4 changes: 2 additions & 2 deletions Sources/UIScrollViewDelegates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension JTAppleCalendarView: UIScrollViewDelegate {
return
}
if directionVelocity == 0.0 {
decelerationRate = UIScrollViewDecelerationRateFast
decelerationRate = UIScrollView.DecelerationRate.fast
}

let setTargetContentOffset = {
Expand Down Expand Up @@ -193,7 +193,7 @@ extension JTAppleCalendarView: UIScrollViewDelegate {
calculatedOffSet = attrib.frame.origin.y
}
} else if calendarViewLayout.thereAreHeaders,
let attrib = layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: attribPath) { // JT101 this was changed
let attrib = layoutAttributesForSupplementaryElement(ofKind: UICollectionView.elementKindSectionHeader, at: attribPath) { // JT101 this was changed
// change the final value to the end of the header
if isScrollingForward() {
calculatedOffSet = attrib.frame.origin.y + attrib.frame.size.height
Expand Down
10 changes: 5 additions & 5 deletions Sources/UserInteractionFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,18 @@ extension JTAppleCalendarView {
/// Registers a class for use in creating supplementary views for the collection view.
/// For now, the calendar only supports: 'UICollectionElementKindSectionHeader' for the forSupplementaryViewOfKind(parameter)
open override func register(_ viewClass: AnyClass?, forSupplementaryViewOfKind elementKind: String, withReuseIdentifier identifier: String) {
super.register(viewClass, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: identifier)
super.register(viewClass, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: identifier)
}

/// Registers a class for use in creating supplementary views for the collection view.
/// For now, the calendar only supports: 'UICollectionElementKindSectionHeader' for the forSupplementaryViewOfKind(parameter)
open override func register(_ nib: UINib?, forSupplementaryViewOfKind kind: String, withReuseIdentifier identifier: String) {
super.register(nib, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: identifier)
super.register(nib, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: identifier)
}

/// Dequeues re-usable calendar cells
public func dequeueReusableJTAppleSupplementaryView(withReuseIdentifier identifier: String, for indexPath: IndexPath) -> JTAppleCollectionReusableView {
guard let headerView = dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader,
guard let headerView = dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader,
withReuseIdentifier: identifier,
for: indexPath) as? JTAppleCollectionReusableView else {
developerError(string: "Error initializing Header View with identifier: '\(identifier)'")
Expand Down Expand Up @@ -447,7 +447,7 @@ extension JTAppleCalendarView {
public func scrollToDate(_ date: Date,
triggerScrollToDateDelegate: Bool = true,
animateScroll: Bool = true,
preferredScrollPosition: UICollectionViewScrollPosition? = nil,
preferredScrollPosition: UICollectionView.ScrollPosition? = nil,
extraAddedOffset: CGFloat = 0,
completionHandler: (() -> Void)? = nil) {

Expand Down Expand Up @@ -478,7 +478,7 @@ extension JTAppleCalendarView {
let sectionIndexPath = self.pathsFromDates([date])[0]

// Ensure valid scroll position is set
var position: UICollectionViewScrollPosition = self.scrollDirection == .horizontal ? .left : .top
var position: UICollectionView.ScrollPosition = self.scrollDirection == .horizontal ? .left : .top
if !self.scrollingMode.pagingIsEnabled(),
let validPosition = preferredScrollPosition {
if self.scrollDirection == .horizontal {
Expand Down

0 comments on commit 50e237b

Please sign in to comment.