例如,有两种模型Realm Information
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 = ""
}
并且有一定的功能
func test(object: AnyObject) {
}
当呼叫作为参数转移时#realm.objects(音乐)[0]'
let realm = try! Realm()
test(realm.objects(Music)[0])
我可以签入功能,该对象属于一个类'音乐'或者下载音乐'
答案 0 :(得分:2)
试试这个:
func test(object: AnyObject) {
if object is Music {
print("music")
} else if object is DownloadMusic {
print("downloadmusic")
}
}