I am using core data to save user input in an array. Until then the code works perfectly , the problem is the time to get some element of that array and put in UITextField as a text. 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()
//Get the info on the 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
}
}

And this is where I am saving the user input, which is located in another View Controller:
@IBAction func saveOnData(sender: AnyObject) {
var quoteInputText = quoteInput.text
var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
var context:NSManagedObjectContext = appDel.managedObjectContext!
var newQuote = NSEntityDescription.insertNewObjectForEntityForName("BookArray", inManagedObjectContext: context) as! NSManagedObject
newQuote.setValue(quoteInputText, forKey: "myFirstBook")
context.save(nil)
println(newQuote)
}
