Anyobject? Does Not Have a Member Named "Removeatindex"

Anyobject? does not have a member named removeAtIndex

removeAtIndex() is not a method on NSArray or AnyObject. You can try to convert your NSArray to a Swift Array and then call that method.

if var citiesArr = citiesArray as? Array<AnyObject>{
citiesArr.removeAtIndex(0)
}

removeObjectAtIndex() is also available on NSMutableArray if you want to use that instead.

AnyObject? does not have a member named 'objectAtIndex'

Getting value from NSDictionary or NSArray return AnyObject object. So you should type cast to appropriate type. Try this

println(((jsonResult.objectAtIndex(0) as NSDictionary).objectForKey("name") as NSArray).objectAtIndex(0))

Immutable Value Of Type [AnyObject] Only Has Mutating Members named 'removeAtIndex'

The return type is constant array which is immutable. You should create a copy of the array to make it mutable. And value type are copied in Swift when you simply assign it to another variable.

var itemArray = selectedFolder.itemArray() // notice var which makes it mutable
itemArray.removeAtIndex(indexPath.row)

And, use itemArray then after.

AnyObject?' does not have a member named 'count'

If you store an array to the user defaults, you should try to cast it to an array when you extract it.

If toDoItems is defined as an array of strings [String], then you just have to use optional binding combined with optional cast, and just copy the extracted array to toDoItems:

if let storedToDoItems: [String] = NSUserDefaults.standardUserDefaults().objectForKey("toDoItems") as? [String] {
toDoItems = storedToDoItems
}

Being an array a struct, i.e. a value type, it is assigned by copy, so when assign storedToDoItems to toDoItems, a copy of it is created and assigned - so you don't need to manually add each element individually.

Your code instead has 2 errors:

  • you have defined storedToDoItems as an optional AnyObject, and optionals don't have a count property.
  • even if it is not defined as optional, AnyObject doesn't have a count property as well. It's irrelevant that the actual type stored in the variable is an array, the variable is declared as AnyObject and that is how is treated by the compiler.

[AnyObject]? does not have a member named 'mutableCopy'

The fetchedObjects property of NSFetchedResultsController is defined as [AnyObject]? - so you don't have to convert it to NSArray or NSMutableArray - just use it as is.

Since an array in swift is a value type, it is always copied by value and not by reference, which means a copy is created by just assigning to a variable. So in:

var sortingArray = fetchedResultsController?.fetchedObjects

a copy of fetchedObjects will be copied into sortingArray.

SWIFT - 'AnyObject' does not have a member name 'fooBar'

executeFetchRequest returns an optional array of AnyObject. You shouldn't force-unwrap it (this can cause a crash). So optionally unwrap it and do an optional cast (as?) to make sure the type is correct:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext!
let req = NSFetchRequest(entityName: "storedItems")

let name:String = results[indexPath.row].name
req.predicate = NSPredicate(format: "name == %@", name)
req.returnsObjectsAsFaults = false

let tapResults = context.executeFetchRequest(req, error: nil)

if let presentResults = tapResults {
if let castedResults = presentResults as? [MyManagedObjectSubclass] {
for item in castedResults {
println(item)
println(item.name)
println(item.subText)
}
}
}
}

I also changed all of your vars to lets since they don't need to be mutable.

Just replace MyManagedObjectSubclass with whatever your NSManagedObject subclass is.

Value of type 'ArrayAny?' has no member 'removeAtIndex'

 var arr = Array<Any>()
arr = ["1","2","3"]
arr.remove(at: 2)
print(arr) // It prints ["1","2"]

In Array, we don't have removeAtIndex() . Use remove(at: Int)



Related Topics



Leave a reply



Submit