如何检查什么类属于AnyObject?

例如,有两个模型领域信息

import Foundation import RealmSwift class Music: Object { dynamic var id = "" dynamic var title = "" dynamic var url = "" } class DownloadMusic: Object { dynamic var id = "" dynamic var title = "" dynamic var path = "" } 

并有一定的function

 func test(object: AnyObject) { } 

当一个调用作为一个parameter passing'realm.objects(Music)[0]'

 let realm = try! Realm() test(realm.objects(Music)[0]) 

我可以检查function,对象属于一个类“音乐”或“下载音乐”

尝试这个:

 func test(object: AnyObject) { if object is Music { print("music") } else if object is DownloadMusic { print("downloadmusic") } }