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 optionalAnyObject
, and optionals don't have acount
property. - even if it is not defined as optional,
AnyObject
doesn't have acount
property as well. It's irrelevant that the actual type stored in the variable is an array, the variable is declared asAnyObject
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 var
s to let
s 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
Querying Geohashes in Firestore Returns Nothing
Custom Markers Disappear on Zoomin The Map and Appear on Zoomout The Map with Clustering
How to Set a Known Position and Orientation as a Starting Point of Arkit
Closure Identity in Swift: Unregister Observing Closure
Actions Assigned to Nsmenuitem Dont Seem to Work
List Is Not Conforming to Encodable
Swift - Connect Delegate to Custom Xib Cell
Why Does a Function Have Long-Term Write Access to All of Its In-Out Parameters
Convert Input Data to Integer in Swift
Swift Bug? Calling Super Class Method When Subclass with Generic Type
List Scroll Freeze on Catalyst Navigationview
Swift Auto Completion Not Working in Xcode 6 Beta
How to Create Viewcontrollers Without Storyboard and Set One as Delegate of The Other One
3 Component Dynamic Multi UIpickerview Swift
Pass and Print All Cases in an Enum in Swift
Swiftui Remove Transition of Fullscreen Cover
Swiftui Change on Multilevel Children Published Object Change