ios7 - MKPolygon using Swift (Missing argument for parameter 'interiorPolygons' in call) -


fellow devs, i'm trying implement polygon overlay on mapview follows:

private func drawoverlayforobject(object: mystruct) {     if let coordinates: [cllocationcoordinate2d] = object.geometry?.coordinates {         let polygon = mkpolygon(coordinates: coordinates, count: coordinates.count)         self.mapview.addoverlay(polygon)     } } 

the following error presented:

missing argument parameter 'interiorpolygons' in call

according documentation: apple docu:

mutable pointers

when function declared taking unsafemutablepointer argument, can accept of following:

  • nil, passed null pointer
  • an unsafemutablepointer value
  • an in-out expression operand stored lvalue of type type, passed address of lvalue
  • an in-out [type] value, passed pointer start of array, , lifetime-extended duration of call

now think approach correct, providing [cllocationcoordinate2d] array. did experience same problem , found workaround?

thanks ronny

the error you're getting swift's cryptic way of saying can't find method matches parameters. if did try passing interiorpolygons parameter, you'd equally confusing:

extra argument 'interiorpolygons' in call

your code pretty close though; need couple of minor changes. in doc reference, says 1 of things can pass is:

an in-out [type] value, passed pointer start of array, , lifetime-extended duration of call

so, it's looking in-out parameter. done passing coordinates prefixed &, so:

mkpolygon(coordinates: &coordinates, count: coordinates.count) 

but, in-out parameters can't constants. docs:

you can pass variable argument in-out parameter. cannot pass constant or literal value argument, because constants , literals cannot modified.

so, need define coordinates var first:

if var coordinates: [cllocationcoordinate2d] = object.geometry?.coordinates 

which makes entire function this:

private func drawoverlayforobject(object: mystruct) {     if var coordinates: [cllocationcoordinate2d] = object.geometry?.coordinates {         let polygon = mkpolygon(coordinates: &coordinates, count: coordinates.count)         self.mapview.addoverlay(polygon)     } } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -