Using Realm in Swift with generics
<p>I am new to programming
and am having trouble trying to manage data in an iOS app
using Realm with generics.
To separate MVC model clearly I made three swift classes as below</p>

<p>ModelLocator.swift</p>

<pre><code>import UIKit
import RealmSwift

class ModelLocator : NSObject {

    class var sharedInstance : ModelLocator {
        struct Singleton {
            static var instance = ModelLocator()
        }
        return Singleton.instance
    }

    var tasks = TaskModel&lt;Object&gt;()

    override init() {
        print("ModelLocator init!")
    }

    func getTask() -&gt; TaskModel&lt;Object&gt; {
        return tasks
    }

    func setTask(array:TaskModel&lt;Object&gt;) -&gt; TaskModel&lt;Object&gt; {
        tasks = array
        return tasks
    }

}
</code></pre>

<p>ModelData.swift</p>

<pre><code>import UIKit
import RealmSwift

let realm = try! Realm()

class TaskModel &lt;T: Object&gt;: NSObject {

    var resources : Results&lt;T&gt;!

    func getResources() -&gt; Results&lt;T&gt; {
        return resources
    }

    func fetchData(database: T) {
        self.resources = try! Realm().objects(database.dynamicType).sorted("date", ascending: false)
    }

    func saveTaskData(number : Int, item : T ){
        let taskData:TaskData = TaskData()
        try! realm.write {
            switch number {
            case 0:
                taskData.id = item as! Int
                break
            case 1:
                taskData.title = item as! String
                break
            default:
                break
            }
        }
    }

}
</code></pre>

<p>TaskData.swift</p>

<pre><code>import RealmSwift

class TaskData: Object {

    dynamic var id = 0    
    dynamic var title = ""
    dynamic var category: Category?
    // category.id:Int, category.name:String, category.priority:Int
    dynamic var contents = "" 
    dynamic var date = NSDate()

    /* set id as primary */
    override static func primaryKey() -&gt; String {
        return "id"
    }

}
</code></pre>

<p>and called it in ViewController.swift as below</p>

<p>ViewController</p>

<pre><code>import UIKit
import RealmSwift

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var tbView: UITableView!

    var taskModel: TaskModel&lt;Object&gt; = TaskModel()
    var taskArray: Results&lt;TaskData&gt;?
    var category: Category = Category()

    override func viewDidLoad() {
        super.viewDidLoad()

        let modelLocator = ModelLocator()
        taskModel = modelLocator.getTask()
        let database = "TaskData"
        taskArray = taskModel.fetchData(TaskData) // &lt;- Where there is error in line  
        print(taskArray)
</code></pre>

<p>On Build, the line above shows an error saying</p>

<blockquote>
  <p>"cannot convert value of type'(TaskData).Type' (aka 'TaskData.Type') to expected argument type 'Object'"</p>
</blockquote>

<p>I know that the type in left and right does not match, but can't figure out how to correct it. (The meaning aka is unfamiliar to me and googling it did not help me as well) </p>

<p>Can anyone tell me how I should fix this code?</p>