Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can core-plot be used with Swift? #96

Closed
marklivingstone opened this issue Jul 23, 2014 · 40 comments

Comments

Projects
None yet
@marklivingstone
Copy link

commented Jul 23, 2014

I am wondering if anyone has successfully used core-plot with Swift yet? Are there any tutorials or sample code available?

@mike-lischke

This comment has been minimized.

Copy link

commented Jul 23, 2014

That's probably better suited for sites like www.stackoverflow.com, not an issue tracker.

@marklivingstone

This comment has been minimized.

Copy link
Author

commented Jul 23, 2014

Hi Mike,

Thanks for your comment. In fact I went to www.stackoverflow.com and
searched for "core-plot swift" and found exactly one message where the OP,
after trying the answer, comments it did not work.

Since I am just starting out with both core-plot and swift, I wanted
reassurance from the core-plot devs or others whether they had tried it yet?

Cheers,

MarkL

Kind Regards,

Mark Livingstone

PhD Candidate
G23_2.31
Institute for Integrated and Intelligent Systems
School of Information and Communication Technology
Griffith University, Gold Coast campus
Queensland, 4222, Australia

E-mail: mark.livingstone@griffithuni.edu.au

On 23 July 2014 16:37, Mike Lischke notifications@github.com wrote:

That's probably better suited for sites like www.stackoverflow.com, not
an issue tracker.


Reply to this email directly or view it on GitHub
#96 (comment).

@mike-lischke

This comment has been minimized.

Copy link

commented Jul 23, 2014

I understand, but still this is not a question for an issue tracker. You report problems here or ask for enhancements, not to get support.

And no, I haven't heard of any user of coreplot having tried to use it with swift.

@eskroch eskroch added the Question label Jul 23, 2014

@eskroch

This comment has been minimized.

Copy link
Member

commented Jul 23, 2014

I'm working on converting one of the example apps to use Swift, but it's not done yet.

Mike's right, questions belong on StackOverflow or the discussion board.

@eskroch eskroch closed this Jul 23, 2014

@eskroch

This comment has been minimized.

Copy link
Member

commented Jul 29, 2014

Right now, with Xcode 6 beta 4, it's not looking easy (or maybe even possible) to use Core Plot from Swift for anything other than pie charts. The problem is a lot of methods that take NSDecimal parameters. Swift does not support bit fields in structs, which means any function or method that references NSDecimal does not get imported into Swift code. If Apple does not add support for NSDecimal in Swift, we'll need to look at redesigning the Core Plot API to accommodate this.

@eskroch

This comment has been minimized.

Copy link
Member

commented Aug 7, 2014

This is still an issue with Xcode 6 beta 5. If Apple does not address this before releasing Swift 1.0, we will look into updating the Core Plot API so it can be used from Swift.

@eskroch eskroch reopened this Aug 7, 2014

@pedrozaj

This comment has been minimized.

Copy link

commented Aug 19, 2014

Xcode 6 beta 6 was released, does it work there? i'm hoping because I really want to use this api :)

@eskroch

This comment has been minimized.

Copy link
Member

commented Aug 20, 2014

No, still no NSDecimal support in Xcode beta 6. :-(

@vlovich

This comment has been minimized.

Copy link

commented Aug 30, 2014

I believe swift has NDecimalNumber, although I image there would be a performance cost associated with switching wholesale to that.

@eskroch

This comment has been minimized.

Copy link
Member

commented Aug 30, 2014

Switching all of the external API methods that currently take NSDecimal numbers to NSDecimalNumber or NSNumber is one possible solution to this problem. That's a major API change that will either break a lot of existing code (the 2.0 release is a good time to do that) or require maintaining two versions of many methods for a while.

I want to wait until the Swift language reaches 1.0 before undertaking a big change like this. If Swift gains support for NSDecimalor a native decimal type bridged to NSDecimal, we won't need to make this change.

@china-maid

This comment has been minimized.

Copy link

commented Sep 17, 2014

May I ask what's the progress of this issue?
We may need do some workaround for it's using swift and CorePlot ...

@eskroch

This comment has been minimized.

Copy link
Member

commented Sep 17, 2014

I've done some changes to the Core Plot API to replace all external references to NSDecimal with NSNumber. This way you can still use decimals if the extra precision is needed (via NSDecimalNumber), but between NSNumber literals in Objective-C and the automatic bridging in Swift, it's much easier to use. I want to do a little more testing before I push it up to GitHub. I'm hoping to have this done by the coming weekend.

@china-maid

This comment has been minimized.

Copy link

commented Sep 18, 2014

@eskroch It's great thank you Eric!

@eskroch

This comment has been minimized.

Copy link
Member

commented Sep 21, 2014

I pushed my Swift updates to the release-2.0 branch. I changed the type of all externally visible methods and properties from NSDecimal to NSNumber and/or supplemented them with equivalent ones with the new type. I updated all of the example apps to work with the new API and translated two of them (DatePlot and the iPhone version of CPTTestApp) to Swift. They compile, but I can't test them right now so please report any problems.

@china-maid

This comment has been minimized.

Copy link

commented Sep 21, 2014

Thanks Eric, really appreciate your work. I'll try report you later.

@leapit

This comment has been minimized.

Copy link

commented Sep 22, 2014

really nice job,maybe I'll try,Thanks!

@china-maid

This comment has been minimized.

Copy link

commented Sep 22, 2014

@eskroch Sorry Eric I didn't noticed 2.0 branch is still under developing, which's not the main branch. I may can't report you quickly for I'm working with 1.5.1 release ...

@AllenConquest

This comment has been minimized.

Copy link

commented Sep 30, 2014

@eskroch I am trying to run the Bar Chart example. It compiles fine, but then at run-time I'm getting the error below when setting the graph title. Do you have any idea what could be causing this?

2014-09-30 17:46:08.897 EnergySys CR[96477:6168404] +[CPTTextStyle textStyleWithAttributes:]: unrecognized selector sent to class 0x12f668
2014-09-30 17:46:08.900 EnergySys CR[96477:6168404] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[CPTTextStyle textStyleWithAttributes:]: unrecognized selector sent to class 0x12f668'
*** First throw call stack:
(
0 CoreFoundation 0x00593df6 exceptionPreprocess + 182
1 libobjc.A.dylib 0x0216ea97 objc_exception_throw + 44
2 CoreFoundation 0x0059b915 +[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x004e49c7 __forwarding
+ 1047
4 CoreFoundation 0x004e458e _CF_forwarding_prep_0 + 14
5 EnergySys CR 0x00097a17 -[CPTGraph setAttributedTitle:] + 375
6 EnergySys CR 0x0008c632 TFC12EnergySys_CR14ViewController13viewDidAppearfS0_FSbT + 7250
7 EnergySys CR 0x0008c85f TToFC12EnergySys_CR14ViewController13viewDidAppearfS0_FSbT + 63
8 UIKit 0x011131a3 -[UIViewController _setViewAppearState:isAnimating:] + 629
9 UIKit 0x011137c0 -[UIViewController __viewDidAppear:] + 171
10 UIKit 0x0111564e __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke + 44
11 UIKit 0x01113e4b -[UIViewController _executeAfterAppearanceBlock] + 63
12 UIKit 0x00fe1654 ___afterCACommitHandler_block_invoke_2 + 33
13 UIKit 0x00fe15d9 _applyBlockToCFArrayCopiedToStack + 415
14 UIKit 0x00fe1412 _afterCACommitHandler + 581
15 CoreFoundation 0x004b6fbe CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30
16 CoreFoundation 0x004b6f00 __CFRunLoopDoObservers + 400
17 CoreFoundation 0x004ac93a __CFRunLoopRun + 1226
18 CoreFoundation 0x004ac1ab CFRunLoopRunSpecific + 443
19 CoreFoundation 0x004abfdb CFRunLoopRunInMode + 123
20 GraphicsServices 0x03fcc24f GSEventRunModal + 192
21 GraphicsServices 0x03fcc08c GSEventRun + 104
22 UIKit 0x00fb7e16 UIApplicationMain + 1526
23 EnergySys CR 0x0008e5de top_level_code + 78
24 EnergySys CR 0x0008e61b main + 43
25 libdyld.dylib 0x03b30ac9 start + 1
26 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

@eskroch

This comment has been minimized.

Copy link
Member

commented Oct 1, 2014

The +[CPTTextStyle textStyleWithAttributes:] method is in a category on CPTTextStyle. Make sure your app is linking Objective-C categories. Linker flag -ObjC.

@AllenConquest

This comment has been minimized.

Copy link

commented Oct 1, 2014

@eskroch I'll give that a try. But I'm also having problems with Xcode crashing when I include the core-plot project. The messages I'm getting in my console are:

Oct 1 07:04:58 Allens-MacBook-Pro.local CoreSimulatorService[19706] : Error Domain=com.apple.CoreSimulator.SimError Code=146 "Unable to lookup in current state: Shutdown" UserInfo=0x7fc239c1aaf0 {NSLocalizedDescription=Unable to lookup in current state: Shutdown}
Oct 1 07:04:58 Allens-MacBook-Pro.local CoreSimulatorService[19706] : Error Domain=com.apple.CoreSimulator.SimError Code=146 "Unable to lookup in current state: Shutdown" UserInfo=0x7fc239c1aaf0 {NSLocalizedDescription=Unable to lookup in current state: Shutdown}
Oct 1 07:05:00 Allens-MacBook-Pro.local CoreSimulatorService[19706] : Could not register service com.apple.coreservices.lsuseractivity.simulatorsupport: Failed to lookup com.apple.coreservices.lsuseractivity.simulatorsupport: 0x44e

Have you seen anything like this before?

@dmelgar

This comment has been minimized.

Copy link

commented Nov 18, 2014

I'm trying to decide what graphing library to use with Swift and am trying to use CorePlot. @eskroch on 9/21 said all signatures in 2.0 branch were changed to use something other than NSDecimal. And it looks like 2.0 was merged with master, yet when I look at CPTXYPlotSpace it still has setLength(NSDecimal).

Has the API been updated to remove requirement of using NSDecimal? Thanks

@eskroch

This comment has been minimized.

Copy link
Member

commented Nov 18, 2014

I haven't merged the latest set of changes on the 2.0 branch back to master. It will happen soon. You can use the code on the release-2.0 branch in the mean time.

@dmelgar

This comment has been minimized.

Copy link

commented Nov 19, 2014

Awesome! Thanks!
I was going down the path of writing protocols and/or creating a separate interface class in Obj-C to deal with core-plot. The altered signatures are working great!

@veronicaTsao

This comment has been minimized.

Copy link

commented Feb 4, 2015

i am trying to use the core-plot with swift. But I have trouble to set the title location. From what I debugged, it seems that the interfaces in the CPTUtilities.h are still using the NSDecimal, and other interfaces to position the ticks and legend are still using NSDecimal. I have a hard time to use core-plot as the library in swift. Can you help?

@veronicaTsao

This comment has been minimized.

Copy link

commented Feb 4, 2015

For instance, the viewCoordinateForViewLength in the CPTXYPlotSpace still takes the NSDecimal as the input parameters which cannot plot the title locations correctly. Or I misunderstood something here. Can you give an example in swift to plot a scattered plot with title, ticks, legend, etc?

@eskroch

This comment has been minimized.

Copy link
Member

commented Feb 5, 2015

The viewCoordinateForViewLength methods are internal to the CPTXYPlotSpace class and shouldn't be called by clients. Two of the example apps (DatePlot and the iPhone version of CPTTestApp) have been converted to Swift.

@veronicaTsao

This comment has been minimized.

Copy link

commented Feb 5, 2015

Thanks. The problem was that I was trying to use plotAreaViewPointForDoublePrecisionPlotPoint which in term calls the viewCoordinateForViewLength.
I do not know if it makes sense, can you make the internal APIs only visible to the package itself, so that when using it as an library, those APIs will not be visible to the caller.

Thanks for all the examples. They are very helpful.

@eskroch

This comment has been minimized.

Copy link
Member

commented Feb 6, 2015

The viewCoordinateForViewLength methods are not declared in the public headers, so you shouldn't see them when importing the Core Plot library or framework.

@veronicaTsao

This comment has been minimized.

Copy link

commented Feb 10, 2015

In order to position the popover at the selected bar, we need to call plotAreaViewPointForPlotPoint to convert the data points to view coordinates, it does not work in swift since the first argument is NSDecimal. Is there any work around? What i am trying to do is to achieve "when a bar is selected, we show a tip of the value and other information". Thanks so much for your guidance.

@eskroch

This comment has been minimized.

Copy link
Member

commented Feb 11, 2015

There's another version that takes an array of doubles (-plotAreaViewPointForDoublePrecisionPlotPoint:numberOfCoordinates:).

I'll add point conversion methods (both directions) that use NSArray that will be easier to use in Swift.

@veronicaTsao

This comment has been minimized.

Copy link

commented Feb 11, 2015

Thanks so much. Can you update when the NSArray version is ready?

@veronicaTsao

This comment has been minimized.

Copy link

commented Feb 11, 2015

quick guidance to use -(CGPoint)plotAreaViewPointForDoublePrecisionPlotPoint:(double )plotPoint numberOfCoordinates:(NSUInteger)count
in swift, should the double
mapped to Double[] or UnsafeMutablePointe

Can you share a simple example to call the API in swift?
Also plotAreaViewPointForDoublePrecisionPlotPoint internally calls the viewCoordinateForViewLength, as discussed above, it uses NSDecimal in the parameter list. Somehow the returned value is always 0.
Can you help?

@gaming-hacker

This comment has been minimized.

Copy link

commented Feb 12, 2015

i'd like to see just a barebones example in swift as well.

@eskroch

This comment has been minimized.

Copy link
Member

commented Feb 13, 2015

@gaming-hacker A couple of the included example apps (DatePlot on the Mac and the iPhone version of CPTTestApp) have been converted to Swift on the release-2.0 branch.

@eskroch

This comment has been minimized.

Copy link
Member

commented Feb 13, 2015

I just added three plot space methods that take an NSArray of coordinate values on the release-2.0 branch.

-(CGPoint)plotAreaViewPointForPlotPoint:(NSArray *)plotPoint;
-(NSArray *)plotPointForPlotAreaViewPoint:(CGPoint)point;
-(NSArray *)plotPointForEvent:(CPTNativeEvent *)event;
@gaming-hacker

This comment has been minimized.

Copy link

commented Feb 13, 2015

i can't get it to build for iOS 8.2

core-plot-release-2.0/examples/CPTTestApp-iPad/Classes/CPTTestApp_iPadViewController.m:79:1: Implementing deprecated method

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h:366:1: Method 'didRotateFromInterfaceOrientation:' declared here

@gaming-hacker

This comment has been minimized.

Copy link

commented Feb 13, 2015

since i'm in landscape mode on my iPad, i just commented out this section and put the frames in viewDidLoad

/*
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if ( UIInterfaceOrientationIsLandscape(fromInterfaceOrientation) ) {
// Move the plots into place for portrait
self.scatterPlotView.frame = CGRectMake(20.0, 55.0, 728.0, 556.0);
self.barChartView.frame = CGRectMake(20.0, 644.0, 340.0, 340.0);
self.pieChartView.frame = CGRectMake(408.0, 644.0, 340.0, 340.0);
}
else {
// Move the plots into place for landscape
self.scatterPlotView.frame = CGRectMake(20.0, 51.0, 628.0, 677.0);
self.barChartView.frame = CGRectMake(684.0, 51.0, 320.0, 320.0);
self.pieChartView.frame = CGRectMake(684.0, 408.0, 320.0, 320.0);
}
}
*/

-(void)viewDidLoad
{
[super viewDidLoad];

[self constructScatterPlot];
[self constructBarChart];
[self constructPieChart];
self.scatterPlotView.frame = CGRectMake(20.0, 51.0, 628.0, 677.0);
self.barChartView.frame    = CGRectMake(684.0, 51.0, 320.0, 320.0);
self.pieChartView.frame    = CGRectMake(684.0, 408.0, 320.0, 320.0);

}

and it works

@gaming-hacker

This comment has been minimized.

Copy link

commented Feb 13, 2015

i found the framework library but where are the headers? usually when a framework is built the headers are included.

@eskroch

This comment has been minimized.

Copy link
Member

commented Feb 14, 2015

The framework will be in build folder inside the Core Plot folder. If the framework built completely, it will include the headers.

#import <CorePlot_iOS/CorePlot.h>
@eskroch

This comment has been minimized.

Copy link
Member

commented Oct 4, 2015

Release 2.0 is out now. There is a [wiki page] that discusses the API changes for this version.

@eskroch eskroch closed this Oct 4, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.