Swift3 error : Type 'NSFastEnumerationIterator.Element' (aka 'Any') does not conform to protocol 'AnyObject'

By : Jenoah
Source: Stackoverflow.com
Question!

So, I'm trying to update my toDo list app to swift 3 / iOS 10, but I came across this error when updating. I have looked up the internet and StackOverflow and found that someone else also sort of had this problem, but the solution there, didn't help for me. This is just one file, that takes care of inserting into Core Data.

This is the code for that file :

import UIKit
import CoreData

var taskMgr: TaskManager = TaskManager()

struct task {
    var name = "not defined"
    var desc = "not defined"
}

class TaskManager: NSObject {
  var tasks = [task]()
  var persistenceHelper: PersistenceHelper = PersistenceHelper()

  override init(){

    let tempTasks:NSArray = persistenceHelper.list(entity: "Task")
    for res:AnyObject in tempTasks{
        tasks.append(task(name:res.valueForKey("name")as! String,desc:res.valueForKey("desc") as! String))
    }
  }


  func addTask(name:String, desc: String){

    var dicTask: Dictionary<String, String> = Dictionary<String,String>()
    dicTask["name"] = name
    dicTask["desc"] = desc

    if(persistenceHelper.save(entity: "Task", parameters: dicTask)){
        tasks.append(task(name: name, desc: desc))
    }
  }

  func removeTask(index:Int){
    let value:String = tasks[index].name 

    if(persistenceHelper.remove(entity: "Task", key: "name", value: value)){
        tasks.remove(at: index)
    }
  }

}

So it gives an error on line 18 which go's like this :

Type 'NSFastEnumerationIterator.Element' (aka 'Any') does not conform to protocol 'AnyObject'

Can anyone help me? Thanks :)

By : Jenoah


Answers

Please Update row 18 like this. I hope this will work for you.

  for res:AnyObject in tempTasks as [AnyObject]


You have to get the collection object first as mentioned below

  var collection = db.collection("simple_document_insert_collection_no_safe");

// Insert a single document collection.insert({hello:'world_no_safe'});

Please refer the below link for more details.

mongod db collection using nodejs



I think you could rewrite this as a single query on the status table, using ORs to test each scenario, like so:

SELECT ss.int_tran_id
FROM   status SS
WHERE  ss.stage in ('ACHPayment_Confirmed', 'HIFV4', 'HIFV5_FTRINF', 'Payment_HIFV5_FTRINF')
OR     (ss.stage = 'PREVDAY'
        AND (EXISTS (SELECT NULL
                     FROM   references rf
                     WHERE  ss.int_tran_id = rf.int_tran_id
                     AND    rf.mid_ref IS NOT NULL)
             OR EXISTS (SELECT NULL
                        FROM   app_data ad
                               INNER JOIN ach aa
                                 ON (ad.app_data_id = aa.ach_id)
                        WHERE  ss.int_tran_id = ad.int_tran_id
                        AND    aa.par_number IS NOT NULL)));
By : Boneist


This video can help you solving your question :)
By: admin