To fetch all lecturers that have a course with the given student, use the predicate
[NSPredicate predicateWithFormat:@"SUBQUERY(courses, $c, ANY $c.students.name == %@).@count > 0", studentName]
Remark: In your first example (fetch all courses for a student), you don't need a SUBQUERY:
[NSPredicate predicateWithFormat:@"ANY students.name == %@", studentName]