小编Dyl*_*lan的帖子

你如何比较Swift中Date的时间

我有两个日期对象:

1: 2017-01-13 11:40:17 +0000

2: 2016-03-15 10:22:14 +0000

我需要比较这些值的时间并忽略日期

例如:上午12:00和上午12:01,晚上12:01(上午12:01>上午12:00)== true

sorting time datetime date swift

8
推荐指数
5
解决办法
1万
查看次数

将ViewController与Swift中的类型进行比较

extension UIViewController {
    func getChildViewController<T>(OfType: T) {
        let classType = Mirror(reflecting: self.childViewControllers.first).subjectType

        if classType == T.self {
            print("there is a match")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是UIViewController的扩展,当您调用此函数时,可以将其传递为一种类型,例如:

ViewController.getChildViewController(OfType: SecondViewController.self)
Run Code Online (Sandbox Code Playgroud)

这将检查视图控制器的第一个孩子是否类型为SecondViewController

但是在if语句中,我得到了错误:

Binary operator '==' cannot be applied to operands of type 'Any.Type' and 'T'
Run Code Online (Sandbox Code Playgroud)

generics comparison uiviewcontroller ios swift

0
推荐指数
1
解决办法
3451
查看次数

标签 统计

swift ×2

comparison ×1

date ×1

datetime ×1

generics ×1

ios ×1

sorting ×1

time ×1

uiviewcontroller ×1