你如何找出一个对象的类型

How do you find out the type of an object

如何知道输入的值是图像、字符串、音频或视频 swift如果有人有想法请帮助我。

在排序中,我想知道对象的类型。

 cell = Chat_CollectionView.dequeueReusableCell(withReuseIdentifier:
   Identifier, for: indexPath)as! SingleChat_Cell 
 let data = sender.object(at: indexPath.row)

现在我想知道数据的数据类型

 cell = Chat_CollectionView.dequeueReusableCell(withReuseIdentifier:
                    Identifier, for: indexPath)as! SingleChat_Cell 

 let data = sender.object(at: indexPath.row)   
 if  (data as? String) != nil { // check if data is String type
        // your code here
 }

 if  (data as? UIImage) != nil { // check if data is UIImage type
        // your code here

 }

 if  (data as? Data) != nil { // check if data is Data type for audio or video
        // your code here

 }

Swift 4

只需使用

print(type(of: data))