Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 4 Issue #44

Open
fuzunspm opened this issue Sep 14, 2017 · 4 comments
Open

Swift 4 Issue #44

fuzunspm opened this issue Sep 14, 2017 · 4 comments

Comments

@fuzunspm
Copy link

Currently it's not working on Swift 4.0. It builds but whenever i try to choose date it crashes with the error below:

*** /Users/x/Desktop/x/x/x/EPCalendarPicker/EPCalendarPicker.swift:254:5: implicit Objective-C entrypoint -[x.EPCalendarPicker collectionView:layout:sizeForItemAtIndexPath:] is deprecated and will be removed in Swift 4; add explicit '@objc' to the declaration to emit the Objective-C entrypoint in Swift 4 and suppress this message 2017-09-14 09:26:27.702076+0300 x[1885:288332] *** /Users/x/Desktop/x/x/x/EPCalendarPicker/EPCalendarPicker.swift:254:5: implicit Objective-C entrypoint -[x.EPCalendarPicker collectionView:layout:sizeForItemAtIndexPath:] is deprecated and will be removed in Swift 4; add explicit '@objc' to the declaration to emit the Objective-C entrypoint in Swift 4 and suppress this message

@clint-liddiard
Copy link

@fuzunspm
Copy link
Author

Now it’s crashes on app delegate I’m on mobile I will paste the error

@fuzunspm
Copy link
Author

whenever i try to choose dates it crashes with the error below. No output to the console

Thread 1: EXC_BAD_ACCESS (code=1, address=0x2000186c)

@hemengohil
Copy link

hemengohil commented Sep 29, 2017

I found the solution.

Step 1. Add this line in EPCalendarPicker.swift, Method : public init(startYear: Int, endYear: Int, multiSelection: Bool, selectedDates: [Date]?)

Lines To Add :
let rect = UIScreen.main.bounds
let screenWidth = rect.size.width - 7
layout.itemSize = CGSize(width: screenWidth/7, height: screenWidth/7)

Step 2 : Remove This Method :
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize
{

    let rect = UIScreen.main.bounds
    let screenWidth = rect.size.width - 7
    return CGSize(width: screenWidth/7, height: screenWidth/7);
}

Add @objc in method to look like :

@objc func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets
{
    return UIEdgeInsetsMake(5, 0, 5, 0); //top,left,bottom,right
}

Everything is working now.

To Show the Calendar call below method :

func showCalender() {
    
    let calendarPicker = EPCalendarPicker(startYear: 2017, endYear: 2099, multiSelection: false, selectedDates: [])
    calendarPicker.calendarDelegate = self
    calendarPicker.startDate = Date()
    calendarPicker.hightlightsToday = true
    calendarPicker.hideDaysFromOtherMonth = true
    calendarPicker.tintColor = UIColor.defaultAppColorDarkBlue
    //        calendarPicker.barTintColor = UIColor.greenColor()
    calendarPicker.dayDisabledTintColor = UIColor.lightGray
    calendarPicker.monthTitleColor = UIColor.black
    calendarPicker.todayTintColor = UIColor.clear
    
    //        calendarPicker.showsTodaysButton = false
    
    calendarPicker.weekendTintColor = UIColor.lightGray
    calendarPicker.weekdayTintColor = UIColor.darkGray
    
    calendarPicker.title = "DATE SELECT"
    calendarPicker.tintColor = UIColor.black
    
    calendarPicker.dateSelectionColor = UIColor.defaultAppColorDarkBlue
    
    let navigationController = UINavigationController(rootViewController: calendarPicker)
    //        self.present(navigationController, animated: true, completion: nil)
    self.present(navigationController, animated: true) {
        navigationController.updateFocusIfNeeded()
        self.view.setNeedsLayout()
    }
    
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants