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

Swift 3.0 beta 6 (acegreen's branch, but with fixes for OS X) #1353

Merged
merged 1 commit into from
Sep 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Charts/Charts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -1527,6 +1528,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate
// 23 is the smallest recommended font size on the TV
font = NSUIFont.systemFont(ofSize: 23, weight: UIFontWeightMedium)
#else
font = NSUIFont.systemFont(ofSize: NSUIFont.systemFontSize)
font = NSUIFont.systemFont(ofSize: NSUIFont.nsuiSystemFontSize)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guess it is supposed to start with NSUI ?

#endif
}

Expand Down
16 changes: 8 additions & 8 deletions Charts/Classes/Charts/PieRadarChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ open class PieRadarChartViewBase: ChartViewBase
#endif

#if os(OSX)
open override func mouseDown(_ theEvent: NSEvent)
open override func mouseDown(with theEvent: NSEvent)
{
// if rotation by touch is enabled
if rotationEnabled
Expand All @@ -641,11 +641,11 @@ open class PieRadarChartViewBase: ChartViewBase

if !_isRotating
{
super.mouseDown(theEvent)
super.mouseDown(with: theEvent)
}
}
open override func mouseDragged(_ theEvent: NSEvent)

open override func mouseDragged(with theEvent: NSEvent)
{
if rotationEnabled
{
Expand All @@ -656,15 +656,15 @@ open class PieRadarChartViewBase: ChartViewBase

if !_isRotating
{
super.mouseDragged(theEvent)
super.mouseDragged(with: theEvent)
}
}
open override func mouseUp(_ theEvent: NSEvent)

open override func mouseUp(with theEvent: NSEvent)
{
if !_isRotating
{
super.mouseUp(theEvent)
super.mouseUp(with: theEvent)
}

if rotationEnabled
Expand Down
20 changes: 10 additions & 10 deletions Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ open class ChartDataEntry: NSObject

open override func isEqual(_ object: Any?) -> Bool
{
let object = object as? AnyObject
if (object === nil)
{
return false
}
if (!object!.isKind(of: type(of: self)))
if (object == nil)
Copy link
Member

@liuxuan30 liuxuan30 Aug 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure which implementation is better.
also the indent seems weird

{
return false
}

let object = object as AnyObject

if (!object.isKind(of: type(of: self)))
{
return false
}
Expand All @@ -68,12 +68,12 @@ open class ChartDataEntry: NSObject
return false
}

if (object!.xIndex != xIndex)
if (object.xIndex != xIndex)
{
return false
}

if (fabs(object!.value - value) > 0.00001)
if (fabs(object.value - value) > 0.00001)
{
return false
}
Expand Down
19 changes: 9 additions & 10 deletions Charts/Classes/Highlight/ChartHighlight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,40 +122,39 @@ open class ChartHighlight: NSObject

open override func isEqual(_ object: Any?) -> Bool
{

let object = object as? AnyObject

if (object === nil)
if (object == nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure which implementation is better

{
return false
}

let object = object as AnyObject

if (!object!.isKind(of: type(of: self)))
if (!object.isKind(of: type(of: self)))
{
return false
}

if (object!.xIndex != _xIndex)
if (object.xIndex != _xIndex)
{
return false
}

if (object!.dataIndex != dataIndex)
if (object.dataIndex != dataIndex)
{
return false
}

if (object!.dataSetIndex != _dataSetIndex)
if (object.dataSetIndex != _dataSetIndex)
{
return false
}

if (object!.stackIndex != _stackIndex)
if (object.stackIndex != _stackIndex)
{
return false
}

if (object!.value != value)
if (object.value != value)
{
return false
}
Expand Down
38 changes: 28 additions & 10 deletions Charts/Classes/Utils/ChartPlatform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple
UIGraphicsBeginImageContextWithOptions(size, opaque, scale)
}

extension NSUIFont {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why, but the indent seems not 4 spaces..

static var nsuiSystemFontSize: CGFloat {
return NSUIFont.systemFontSize
}
}

#endif

#if os(OSX)
Expand All @@ -221,6 +227,12 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple
public typealias NSUIRotationGestureRecognizer = NSRotationGestureRecognizer
public typealias NSUIScreen = NSScreen

extension NSUIFont {
static var nsuiSystemFontSize: CGFloat {
return NSUIFont.systemFontSize()
}
}

/** On OS X there is no CADisplayLink. Use a 60 fps timer to render the animations. */
open class NSUIDisplayLink
{
Expand Down Expand Up @@ -251,7 +263,7 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple
_self._target?.performSelector(onMainThread: _self._selector, with: _self, waitUntilDone: false)

return kCVReturnSuccess
}, UnsafeMutablePointer(unsafeAddress(of: self)))
}, Unmanaged.passUnretained(self).toOpaque())
}
else
{
Expand Down Expand Up @@ -375,7 +387,7 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple

open class NSUIView: NSView
{
open final override var isFlipped: Bool
open override var isFlipped: Bool
{
return true
}
Expand All @@ -385,17 +397,17 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple
self.setNeedsDisplay(self.bounds)
}

open final override func touchesBegan(with event: NSEvent)
open override func touchesBegan(with event: NSEvent)
{
self.nsuiTouchesBegan(event.touches(matching: .any, in: self), with: event)
}

open final override func touchesEnded(with event: NSEvent)
open override func touchesEnded(with event: NSEvent)
{
self.nsuiTouchesEnded(event.touches(matching: .any, in: self), with: event)
}

open final override func touchesMoved(with event: NSEvent)
open override func touchesMoved(with event: NSEvent)
{
self.nsuiTouchesMoved(event.touches(matching: .any, in: self), with: event)
}
Expand Down Expand Up @@ -503,9 +515,8 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple

func NSUIGraphicsPushContext(_ context: CGContext)
{
let address = unsafeAddress(of: context)
let ptr: UnsafeMutablePointer<CGContext> = UnsafeMutablePointer(UnsafePointer<CGContext>(address))
let cx = NSGraphicsContext(graphicsPort: ptr, flipped: true)
let address = Unmanaged.passUnretained(context).toOpaque()
let cx = NSGraphicsContext(graphicsPort: address, flipped: true)
NSGraphicsContext.saveGraphicsState()
NSGraphicsContext.setCurrent(cx)
}
Expand Down Expand Up @@ -550,8 +561,8 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple

let colorSpace = CGColorSpaceCreateDeviceRGB()
let ctx = CGContext(data: nil, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 4*width, space: colorSpace, bitmapInfo: (opaque ? CGImageAlphaInfo.noneSkipFirst.rawValue : CGImageAlphaInfo.premultipliedFirst.rawValue))
ctx?.concatCTM(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: CGFloat(height)))
ctx?.scale(x: scale, y: scale)
ctx?.concatenate(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: CGFloat(height)))
ctx?.scaleBy(x: scale, y: scale)
NSUIGraphicsPushContext(ctx!)
}
}
Expand Down Expand Up @@ -586,6 +597,13 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple
return NSUIScreen.main()
}

extension NSParagraphStyle {
// This, oddly, is different on iOS (default is a static function on OS X)
static var `default`: NSParagraphStyle {
return NSParagraphStyle.default()
}
}

extension NSString {
/** On OS X, only size(withAttributes:) exists. It is expected that OSX will catch up and also change to
size(attributes:). For now, use this as proxy. */
Expand Down
15 changes: 7 additions & 8 deletions Charts/Classes/Utils/ChartSelectionDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,29 @@ open class ChartSelectionDetail: NSObject

open override func isEqual(_ object: Any?) -> Bool
{

let object = object as? AnyObject

if (object === nil)
if (object == nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

{
return false
}

let object = object as AnyObject

if (!object!.isKind(of: type(of: self)))
if (!object.isKind(of: type(of: self)))
{
return false
}

if (object!.value != _value)
if (object.value != _value)
{
return false
}

if (object!.dataSetIndex != _dataSetIndex)
if (object.dataSetIndex != _dataSetIndex)
{
return false
}

if (object!.dataSet !== _dataSet)
if (object.dataSet !== _dataSet)
{
return false
}
Expand Down