"Ambiguous Use of 'Children'" When Trying to Use Nstreecontroller.Arrangedobjects in Swift 3.0

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



Leave a reply



Submit