I'm using core data to save the user's input into an array. Until then the code works perfectly, the problem is to pick up some element of that array and put it in the UITextField. The code has no errors, just does not work as it should.
@IBOutlet weak var quoteTextField: UILabel!
@IBOutlet weak var addQuote: UIButton!
@IBOutlet weak var deleteQuote: UIButton!
var bookArray: Array<AnyObject> = []
override func viewDidLoad() {
super.viewDidLoad()
//Pega todas as quotes guardadas no CoreData
var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
var context:NSManagedObjectContext = appDel.managedObjectContext!
var request = NSFetchRequest(entityName: "BookArray")
request.returnsObjectsAsFaults = false
bookArray = context.executeFetchRequest(request, error: nil)!
if (bookArray.count != 0){
var randomIndex = Int(arc4random_uniform(UInt32(bookArray.count)))
quoteTextField.text = bookArray[randomIndex] as? String
}
}