var callback:(value:AnyObject[]);
init(selectedCall:(value:AnyObject[]), arrays: Array<AnyObject> ... )
let returnValue = { (selectedRows: AnyObject[]) in
println("selected row \(selectedRows)");
};
// Pass the callback to the new delegate, as well as the list of arrays.
var delegate=PickerProvider(selectedCall:returnValue
,arrays:numDice,dieTypes,modRolls,modifiers);
This resulted in the compile time error of:
What really happened is explained in Apple's swift manual in a note under functions:
'(value: @lvalue AnyObject[]) -> $T3' is not identical to '(value: AnyObject[])'
'(AnyObject[]) -> ()' is not convertible to 'AnyObject[]'
Strictly speaking, the
sayGoodbye
function does still return a value, even though no return value is defined. Functions without a defined return type return a special value of type Void
. This is simply an empty tuple, in effect a tuple with zero elements, which can be written as ()
.(selectedRows: AnyObject[])->()
While the compiler will currently let you declare variables and member functions without the ->(), it will not consider those the same as the real function.
The solution to this one is to declare my code as:
var callback:(value:AnyObject[])->();
With an initializer of:
init(selectedCall:(value:AnyObject[])->(), arrays: Array<AnyObject> ... )
No comments:
Post a Comment