Can you pass a typed array to a function within an enum in swift? -
in swift app, i've created enum function takes array of clbeacon objects it's argument (i.e., [clbeacon]
). no clang errors enum, when try use enum, clang complains can't invoke function argument list of ([clbeacon])
. here's code:
enum beaconarraystate { case noobjectonscreen, firstobjectonscreen, firstobjectoffscreen mutating func check(beacons: [clbeacon]) -> beaconarraystate { switch self { case firstobjectonscreen: return .firstobjectonscreen case firstobjectoffscreen: return .firstobjectoffscreen case noobjectonscreen: if beacons.count > 0 { println("push screen associated beacon \(beacons[0].minor)") } return .noobjectonscreen } } } var beaconarraystate: beaconarraystate = .noobjectonscreen func beaconmanager(manager: anyobject!, didrangebeacons beacons: [anyobject]!, inregion region: clbeaconregion!) { let knownbeacons = beacons.filter{$0.proximity != clproximity.unknown} //send updated beacons array perform parsebeacons nsnotificationcenter.defaultcenter().postnotificationname("updatenotificationpriorities", object: knownbeacons) beaconarraystate = beaconarraystate.check(knownbeacons [clbeacon]) }
this gives: error - cannot invoke 'check' argument list of type '([clbeacon])'
the code in case statements irrelevant , not yet determined, why error on invocation?
the problem code calling check method statically while function not static @ all. check function not mutating function dont need mutating keyword. make work make follow change beaconarraystate = beaconarraystate.check(knownbeacons [clbeacon])
or if want check method mutate change :
mutating func check(beacons: [clbeacon]) { switch self { case firstobjectonscreen: self = .noobjectonscreen case firstobjectoffscreen: self = .firstobjectoffscreen case noobjectonscreen: if beacons.count > 0 { println("push screen associated beacon \(beacons[0].minor)") } self = .noobjectonscreen } }
then call beaconarraystate.check(knownbeacons [clbeacon])
, becaonarraystate new value
Comments
Post a Comment