Ambiguous use of 'children' when trying to use NSTreeController.arrangedObjects in Swift 3.0
The two candidates for the children
property differ by their type:
Foundation.XMLNode:137:14: note: found this candidate
open var children: [XMLNode]? { get }
^
AppKit.NSTreeNode:12:14: note: found this candidate
open var children: [NSTreeNode]? { get }
^
You can resolve the ambiguity by casting the value of the property
to the expected type. In your case:
let k = (self.arrangedObjects as AnyObject).children as [NSTreeNode]?
`NSTreeController`'s `arrangedObjects` doesn't respond to `children`
When you're using Objective-C, you should look at the Objective-C version of the docs. The page you linked to has a Language selector toward the top-right.
In the Objective-C docs, you'll find that the proxy responds to -childNodes
, not -children
.
Ambiguous use of 'fetch' error
The method fetch
you are using returns [Any]
, because it could be [Dictionary]
or [NSManagedObject]
or one of its subclasses.
You have to cast [Any]
to the proper type
let result = try context.fetch(request!) as! [EntityClassName]
for item in result {
...
}
The forced unwrapping is absolutely safe because according to the fetch request it returns always [EntityClassName]
.
Swift 3 reveals a lot of mistakes made but tolerated in Swift 2 to improve the type safety.
Alternatively you could use the new API with generics, this avoids some type casting.
Related Topics
Realm Error Domain=Io.Realm.Unknown Code=89 "Operation Canceled"
How to Decode Utf8-Literals Like "\Xc3\Xa6" in Swift 5
Swift How to Design Uiwebview Auto Resize Full Screen in Story Board
Example for Drag and Drop Inside Nscollectionview
Get Images from Document Directory Not File Path Swift 3
Uicollectionviewcell Not Forcing Cell Size
Swift:Program for Addition of 2 Numbers Using Closure
Initializer for Conditional Binding Must Have Optional Type, Not '[String:Any]'
Testing If Double from Textfield Has a Value or Not
Xcode 7.1 Beta: Content of File Error
How to Pass Closure as a Parameter in Perform(Selector, Withobject)
Macos Playground: How Can Change the Background Color
How to Make a Variable from a String
Core Data Update in Swift While Selecting Any Row in List Table View Not Working
Swift 3 - How to Insert Tableviewcells from Another View
Checkboxes in Uitableview State Persistence