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

Port to Swift 3 #17

Merged
merged 5 commits into from Jul 21, 2016
@@ -285,11 +285,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0600;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Big Nerd Ranch";
TargetAttributes = {
7D077FD919AEE01200E431A5 = {
CreatedOnToolsVersion = 6.0;
LastSwiftMigration = 0800;
};
7D077FEC19AEE01300E431A5 = {
CreatedOnToolsVersion = 6.0;
@@ -420,8 +421,10 @@
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
@@ -464,6 +467,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
@@ -484,9 +488,12 @@
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = GrafDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = "com.bignerdranch.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "GrafDemo/GrafDemo-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -498,8 +505,12 @@
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = GrafDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = "com.bignerdranch.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "GrafDemo/GrafDemo-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -518,6 +529,7 @@
);
INFOPLIST_FILE = GrafDemoTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.bignerdranch.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GrafDemo.app/Contents/MacOS/GrafDemo";
};
@@ -534,6 +546,7 @@
);
INFOPLIST_FILE = GrafDemoTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.bignerdranch.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GrafDemo.app/Contents/MacOS/GrafDemo";
};
@@ -45,27 +45,27 @@ class BNRArcTypesWindowController: NSWindowController {
raRelativeAngleLabel.stringValue = String(relativeDeltaStringValue)
}
@IBAction func toggleArcClockwise(toggle: NSButton) {
@IBAction func toggleArcClockwise(_ toggle: NSButton) {
arcEditingView.clockwise = toggle.state == NSOnState
}
@IBAction func setStartAngle(slider: NSSlider) {
@IBAction func setStartAngle(_ slider: NSSlider) {
arcEditingView.startAngle = CGFloat(slider.floatValue)
updateSliderLabels()
}
@IBAction func setEndAngle(slider: NSSlider) {
@IBAction func setEndAngle(_ slider: NSSlider) {
arcEditingView.endAngle = CGFloat(slider.floatValue)
updateSliderLabels()
}
@IBAction func setRelativeStartAngle(slider: NSSlider) {
@IBAction func setRelativeStartAngle(_ slider: NSSlider) {
relativeArcEditingView.startAngle = CGFloat(slider.floatValue)
updateSliderLabels()
}
@IBAction func setRelativeDeltaAngle(slider: NSSlider) {
@IBAction func setRelativeDeltaAngle(_ slider: NSSlider) {
relativeArcEditingView.deltaAngle = CGFloat(slider.floatValue)
updateSliderLabels()
}
@@ -43,48 +43,48 @@ public class BNRLinesWindowController: NSWindowController {
linePhaseBox.target = self
linePhaseBox.action = #selector(BNRLinesWindowController.refreshViews(_:))
linePhaseBox.enabled = false
linePhaseBox.isEnabled = false
}
// Called by the line view prior to constructing and stroking the example path
public func setupContext (context: CGContext!) {
CGContextSetLineWidth (context, CGFloat(lineWidthSlider.floatValue))
CGContextSetMiterLimit (context, CGFloat(miterLimitSlider.floatValue))
CGContextSetLineCap (context, CGLineCap(rawValue: Int32(endCapPopUp.indexOfSelectedItem))!)
CGContextSetLineJoin (context, CGLineJoin(rawValue: Int32(lineJoinPopUp.indexOfSelectedItem))!)
public func setupContext (_ context: CGContext!) {
context.setLineWidth (CGFloat(lineWidthSlider.floatValue))
context.setMiterLimit (CGFloat(miterLimitSlider.floatValue))
context.setLineCap (CGLineCap(rawValue: Int32(endCapPopUp.indexOfSelectedItem))!)
context.setLineJoin (CGLineJoin(rawValue: Int32(lineJoinPopUp.indexOfSelectedItem))!)
if self.lineAlphaCheckbox.state == NSOnState {
NSColor.blueColor().colorWithAlphaComponent(0.50).set()
NSColor.blue().withAlphaComponent(0.50).set()
} else {
NSColor.blueColor().set()
NSColor.blue().set()
}
if linePhaseBox.enabled {
if linePhaseBox.isEnabled {
let phase = CGFloat(linePhaseSlider.floatValue)
let lengths = [
dash0Slider.floatValue, space0Slider.floatValue,
dash1Slider.floatValue, space1Slider.floatValue,
dash2Slider.floatValue, space2Slider.floatValue
].map { CGFloat($0) }
CGContextSetLineDash (context, phase, lengths, lengths.count)
context.setLineDash (phase: phase, lengths: lengths, count: lengths.count)
}
}
// A change was made to a control that affects what the render hook uses.
// Don't care what the control was, just cause a redraw to happen.
@IBAction func refreshViews(smarf: NSControl) {
@IBAction func refreshViews(_ smarf: NSControl) {
linesView.needsDisplay = true
swiftLinesView.needsDisplay = true
}
// Two of the checkboxes actually change the lines view configuration.
@IBAction func toggleShowLogicalPath (sender: NSButton) {
@IBAction func toggleShowLogicalPath (_ sender: NSButton) {
linesView.showLogicalPath = (sender.state == NSOnState)
swiftLinesView.showLogicalPath = (sender.state == NSOnState)
}
@IBAction func changeRenderMode (sender: NSPopUpButton) {
@IBAction func changeRenderMode (_ sender: NSPopUpButton) {
linesView.renderMode = BNRLinesViewRenderMode(rawValue: sender.indexOfSelectedItem)!
swiftLinesView.renderMode = LinesView.RenderMode(rawValue: sender.indexOfSelectedItem)!
}
@@ -44,33 +44,29 @@ class BNRPostScriptWindowController: NSWindowController {
@IBAction func draw(_: AnyObject) {
var callbacks = CGPSConverterCallbacks()
guard let converter = CGPSConverterCreate (nil, &callbacks, nil) else {
guard let converter = CGPSConverter (info: nil, callbacks: &callbacks, options: nil) else {
return
}
let code = self.codeText.string
let codeCString = (code as NSString!).UTF8String
guard let provider = CGDataProviderCreateWithData (nil,
codeCString, Int(strlen(codeCString)), nil) else {
guard let codeData = self.codeText.string?.data(using: .utf8),
let provider = CGDataProvider(data: codeData) else {
return
}
let data = NSMutableData()
guard let consumer = CGDataConsumerCreateWithCFData (data) else {
let nsdata = NSMutableData(data: codeData)
guard let consumer = CGDataConsumer (data: nsdata as CFMutableData) else {
return
}
let converted = CGPSConverterConvert (converter, provider, consumer, nil)
let converted = converter.convert (provider, consumer: consumer, options: nil)
if !converted {
print("boo")
print("Could not convert postscript text")
}
let pdfDataProvider = CGDataProviderCreateWithCFData(data)
let pdf = CGPDFDocumentCreateWithProvider(pdfDataProvider)
let pdfDataProvider = CGDataProvider(data: nsdata)
let pdf = CGPDFDocument(pdfDataProvider!)
self.pdfView.pdfDocument = pdf
}
}
Copy path View file
@@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.bignerdranch.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.