What is the datatype of return in this function?

Viewed 85

I created two realm Object classes called : Master and Courses

class Master : Object , Identifiable {
    
    @objc dynamic var id = UUID()
    @objc dynamic var name : String = ""
    var courses = List<Course>()
    
}

class Course : Object , Identifiable {
    
    @objc dynamic var id = UUID()
    @objc dynamic var name : String = ""
    var parentMaster = LinkingObjects(fromType:Master.self , property: "courses")
    
}

ViewModel :

class AppState : ObservableObject {
    
    @Published var allmasters : [Master] = []

}

I have a simple function to return courses for each master here :

   func input(index: Int) -> List<Course> {
       
        return appState.allmasters[index].courses

    }

My problem is : what is the datatype of return for function?? I put List<Course> as a return type but the compiler give me this error :

Generic type 'List' specialized with too few type parameters (got 1, but expected 2)

1 Answers

It seems you are importing both SwiftUI and RealmSwift in the same file, both of which declare a List type.

If you want to return a RealmSwift.List, you need to declare the return type as such.

func input(index: Int) -> RealmSwift.List<Course> {   
    return appState.allmasters[index].courses
}
Related