How to test for the class of a variable in Swift?

前端 未结 4 2239
猫巷女王i
猫巷女王i 2020-12-08 20:15

I want to check if the elements of an Array are a subclass of UILabel in Swift:

import UIKit

var u1 = UILabel()
u1.text=\"hello\"
var u2 = UIView(frame: CGR         


        
4条回答
  •  情歌与酒
    2020-12-08 20:54

    You may compare classes using the following in swift:

     return object.dynamicType == otherObject.dynamicType
    

    dynamicType will return an instance of Class which you may compare

提交回复
热议问题