首页 > 解决方案 > Unable to connect code from a third-party library

问题描述

I try to connect this library, but this error falls in the code. I did not find answers in the forums, what am I doing wrong?

https://github.com/miraan/CalendarDateRangePickerViewController

https://yadi.sk/d/Cze6fOwcrV01tA

let dateRangePickerViewController = 
CalendarDateRangePickerViewController(collectionViewLayout: 
UICollectionViewFlowLayout())
dateRangePickerViewController.delegate = self
let navigationController = UINavigationController(rootViewController: 
dateRangePickerViewController)
self.navigationController?.present(navigationController, animated: true, 
completion: nil)

标签: iosswiftuidatepicker

解决方案


CalendarDateRangePickerViewController自 2 年以来未更新,因此您需要进行一些更改才能使用该库。

在这里,我使用 Xcode 10.1 实现了它,并按照以下步骤使用它。

首先将 pod 添加到您的 pod 文件中。

pod 'CalendarDateRangePickerViewController'

然后使用pod install命令。

然后从 Targets 中选择您的 pod。检查下图。

在此处输入图像描述

然后第 3 步搜索Swift Language Version并选择Swift 3那里。

然后去你想要使用这个库的班级

并添加

import CalendarDateRangePickerViewController

现在您的第三方库已经可以使用了,您可以添加示例代码,如下所示:

import UIKit
import CalendarDateRangePickerViewController

class ViewController: UIViewController, CalendarDateRangePickerViewControllerDelegate {

    func didTapCancel() {

    }

    func didTapDoneWithDateRange(startDate: Date!, endDate: Date!) {

    }


    override func viewDidLoad() {
        super.viewDidLoad()
        let dateRangePickerViewController =
            CalendarDateRangePickerViewController(collectionViewLayout:
                UICollectionViewFlowLayout())
        dateRangePickerViewController.delegate = self
        let navigationController = UINavigationController(rootViewController:
            dateRangePickerViewController)
        self.navigationController?.present(navigationController, animated: true,
                                           completion: nil)
    }
}

这里是更多信息的示例项目

编辑:

但是,每当您在终端中点击pod installpod update命令时,您都需要Swift Language Version再次设置Swift 3


推荐阅读