Delegates not firing in Swift 3 / XCode 8

35 views
Skip to first unread message

Andrew Voelkel

unread,
Oct 20, 2016, 2:34:08 AM10/20/16
to coreplot-discuss
Hi,

I have CorePlot code that works fine in XCode7, but doesn't work in Swift 3 with XCode 8. The problem is that the delegate is not firing:

func number(_ plot: CPTPlot, field fieldEnum: UInt, record idx: UInt) -> Double { .... }


I've tried various things but nothing seems to work. I get a compiler warning that 


Instance method 'number(_:field:record:)' nearly matches optional requirement 'number(for:field:record:)' of protocol 'CPTPlotDataSource'


I've done Google searches on this and the various solutions mentioned there don't seem to work. I've seen in mentioned a couple times that this may be a bug in XCode 8.


I'm surprised not to see this mentioned here as an issue since the function I'm trying to implement as a delegate would seem to be extremely common, so I would think everyone would run into this.


Unless I did something wrong, I have upgraded to the latest core-plot by coping the new .a file and the headers, but I'll double check that.


- Andy

Eric

unread,
Oct 20, 2016, 7:50:05 AM10/20/16
to coreplot-discuss
Swift 3 made some significant changes in how Objective-C names are translated to Swift. The error message tells you exactly what's wrong. The first parameter in your delegate method should have an external name of "for", not "_".

Eric

Andrew Voelkel

unread,
Oct 20, 2016, 10:07:57 AM10/20/16
to coreplot-discuss
I tried that, as well as a number of other things. Actually, what you suggest is what the automatic XCode conversion produced in the first place. But when you try to build you get a warning, and the delegate never fires when you try to update the plot.

No one else is having this problem?? What _is_ the proper swift signature.

I also tried a couple @obc declarations that were suggested on the web. Also no joy.

- Andy

Andrew Voelkel

unread,
Oct 20, 2016, 10:31:46 AM10/20/16
to coreplot-discuss
I think maybe I'm somehow referencing an older 2.0 version of CorePlot. I'm fighting with XCode trying to figure that out. Even after a year, the damn configuration panes still trip me up. Not a great design.

Anyway, ignore this thread until I figure that out.

Andrew Voelkel

unread,
Oct 20, 2016, 7:53:46 PM10/20/16
to coreplot-discuss
I got it working. I was indeed somehow referencing an older version of CorePlot. I took much more mucking around than I expected to get it working with the new version of CorePlot (any my configuration setup doesn't look much like the example code at all).

Anyhow, the code did need an adjustment, which may be the source of the original problem:

func number(for plot: CPTPlot, field fieldEnum: UInt, record idx: UInt) -> Double { .... }

needed to change to: 

func double(for plot: CPTPlot, field fieldEnum: UInt, record idx: UInt) -> Double { .... }

I'm sure this was triggered by the switch to Swift 3.0, but I'm sure there were other problems caused by running CorePlot 2.0 instead of CorePlot 2.2

Reply all
Reply to author
Forward
0 new messages