0

For my Current project I'd like to fill a TableView from my CoreData DB.

I've a Class named Movies(movieNAme, cinemaName, rate)

Thanks to this function :

    var appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
    let context:NSManagedObjectContext = appDel.managedObjectContext
    var request:NSFetchRequest = NSFetchRequest(entityName: "Movies")
    myMovies = context.executeFetchRequest(request, error: nil)

However, I'd like to specify the type of the objects in this array(I want an Array of object Movie)

I've tried that

    var myMovies:Array<Films> ...

but with the Array type, I don't have access to the objectAtIndex method

Any ideas to solve this issue ?

Thanks

2 Answers 2

1

Thanks for your answer ! But I decided to use this instead :

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:    NSIndexPath) -> UITableViewCell {
    let cell:MainTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MainTableViewCell

    println((myMovies.objectAtIndex(indexPath.row) as Movies).name)
    cell.CellTitle.text = (myMovies.objectAtIndex(indexPath.row) as Movies).MovieName)
    return cell
}

But it doesn't work either...

EDIT : It works now ! I missed to link my class to my Entity in CoreData ! Sorry

Sign up to request clarification or add additional context in comments.

Comments

0

you should be able to do myMovies[0], same as objectAtIndex, the reason you don't have objectAtIndex is because it is a Swift array, you can just access the index using []

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.