Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpectedly found nil while unwrapping an Optional value #26

Open
Ged2323 opened this issue Nov 14, 2015 · 0 comments
Open

unexpectedly found nil while unwrapping an Optional value #26

Ged2323 opened this issue Nov 14, 2015 · 0 comments

Comments

@Ged2323
Copy link

Ged2323 commented Nov 14, 2015

This code works the first time though when I run it a second time on the line:

  • result.name = "(result.name! ) ClientChange" I get the error
    (unexpectedly found nil while unwrapping an Optional value)

let moc = CoreDataStack.defaultStack.managedObjectContext

    let task: Task = NSEntityDescription.insertNewObjectForEntityForName("Task", inManagedObjectContext: moc) as! Task
    task.name = "HElaLuia"

    let cycling: Task = NSEntityDescription.insertNewObjectForEntityForName("Task", inManagedObjectContext: moc) as! Task
    cycling.name = "Foolish"

    let biking: Task = NSEntityDescription.insertNewObjectForEntityForName("Task", inManagedObjectContext: moc) as! Task
    biking.name = "Acting"

    let outdoorTasksTag = NSEntityDescription.insertNewObjectForEntityForName("Tag", inManagedObjectContext: moc) as! Tag
    outdoorTasksTag.name = "AnotherTag"

    let newTasksTag = NSEntityDescription.insertNewObjectForEntityForName("Tag", inManagedObjectContext: moc) as! Tag
    newTasksTag.name = "Just Another Tag"
    newTasksTag.task = biking

    outdoorTasksTag.task = cycling


    if moc.hasChanges
    {
        do
        {
            try moc.save()
        }
        catch let error as NSError?
        {
            print("Error Occured \(error!)", terminator: "\n")
        }
    }
    CoreDataStack.defaultStack.seamStore!.triggerSync()



            do
            {
                try moc.save()
            }
            catch
            {
                print("Error thrown baby", terminator: "\n")
            }



            let fetchRequest: NSFetchRequest = NSFetchRequest(entityName: "Task")
            do
            {
                let results = try moc.executeFetchRequest(fetchRequest)
                for result in results as! [Task]
                {


                    result.name = "\(result.name! ) ClientChange"
                    NSLog ("result.name  %@ \n",result);
                }
                try moc.save()
            }
            catch
            {

            }

Also can you give a demo of how to use the cloudKit functionality.
Thank you in Advance. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant