Yes, create 2 entities and create a bi-directional many to many relationship (create a relationship in each direction and set them as inverse of each other). In this way a Teacher can have a relationship to any number of Classes and vice-versa. You do not need a third entity.
You can add an index in Core Data if you need one, it is added to an attribute of your choice by ticking the indexed
option in Xcode.