0

I know that question has been asked many times, but the solutions didn't work with me. I have the following NSManaged object class:

@NSManaged var cellColor: AnyObject
@NSManaged var des: String
@NSManaged var name: String
@NSManaged var switcher: NSNumber

And when trying to assign this value to a var as a bool when loading the managed object, I get an error. This is an example of assigning the value to a var:

func loadData(){
var appDel = UIApplication.sharedApplication().delegate as AppDelegate
var context = appDel.managedObjectContext!
var request = NSFetchRequest(entityName: "Row")
var result:NSArray = context.executeFetchRequest(request, error: nil)!
if result.count > 0 {
    for i in result{

        var name = i.name as String
        var des = i.des as String
        var color = i.cellColor as UIColor
        var switcher:Bool{
            get{

            return i.switcher == NSNumber(bool: true) 
            //the problem    happens here

However, when I try a simple example of casting in this way, It works well.

How to solve that ??

spenibus
  • 4,339
  • 11
  • 26
  • 35
  • I used the integer value (0 and 1) for this case. And the comparison code: i.switcher.integerValue == 1 – phuongle Sep 23 '15 at 02:46

1 Answers1

0

I think it just like this:

for i in results {
    var name = i.name as String
    var des = i.des as String
    var color = i.cellColor as UIColor
    var switcher: Bool {
        return Bool(i.switcher)
    }
}

Didn't test that though.

Prontto
  • 1,671
  • 11
  • 21