This extension works together with SwiftyJSON framework. So is necessary to install SwiftyJSON through CocoaPods, Cartahge o The Swift Package Manager.
Simply copy the file Realm+Utilities.swift to your project and import it in XCode.
let json = realmObject.toJSON()