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 5 support #21

Closed
wants to merge 5 commits into from
Closed
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
5 changes: 3 additions & 2 deletions SwiftLintXcode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 04E4BF271CB25D3100BC7305;
Expand Down Expand Up @@ -254,7 +255,7 @@
PRODUCT_NAME = SwiftLintXcode;
SWIFT_OBJC_BRIDGING_HEADER = "SwiftLintXcode/SwiftLintXcode-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
WRAPPER_EXTENSION = xcplugin;
};
name = Debug;
Expand All @@ -274,7 +275,7 @@
PRODUCT_BUNDLE_IDENTIFIER = net.ypresto.SwiftLintXcode;
PRODUCT_NAME = SwiftLintXcode;
SWIFT_OBJC_BRIDGING_HEADER = "SwiftLintXcode/SwiftLintXcode-Bridging-Header.h";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
WRAPPER_EXTENSION = xcplugin;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
9 changes: 6 additions & 3 deletions SwiftLintXcode/SaveHook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ final class SaveHook {
if swizzled { return }
swizzled = true

let fromMethod = class_getInstanceMethod(NSDocument.self, #selector(NSDocument.save(withDelegate:didSave:contextInfo:)))
let toMethod = class_getInstanceMethod(NSDocument.self, #selector(NSDocument.swiftLintXcodeSaveDocument(delegate:didSaveSelector:contextInfo:)))
guard let fromMethod = class_getInstanceMethod(NSDocument.self, #selector(NSDocument.save(withDelegate:didSave:contextInfo:))),
let toMethod = class_getInstanceMethod(NSDocument.self, #selector(NSDocument.swiftLintXcodeSaveDocument(delegate:didSaveSelector:contextInfo:))) else {
return
}

method_exchangeImplementations(fromMethod, toMethod)
}

Expand All @@ -41,7 +44,7 @@ final class SaveHook {
// https://github.com/travisjeffery/ClangFormat-Xcode/blob/a22114907592fb5d5b1043a4919d7be3e1496741/ClangFormat/NSDocument+TRVSClangFormat.m
extension NSDocument {

dynamic func swiftLintXcodeSaveDocument(delegate: AnyObject?, didSaveSelector: Selector, contextInfo: UnsafeMutableRawPointer) -> Void {
@objc dynamic func swiftLintXcodeSaveDocument(delegate: AnyObject?, didSaveSelector: Selector, contextInfo: UnsafeMutableRawPointer) -> Void {
if SaveHook.tryOnSaveDocument(self) {
// NOTE: Call original method
swiftLintXcodeSaveDocument(delegate: delegate, didSaveSelector: didSaveSelector, contextInfo: contextInfo)
Expand Down
10 changes: 5 additions & 5 deletions SwiftLintXcode/SwiftLintXcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SwiftLintXcode: NSObject {
self.bundle = bundle

super.init()
center.addObserver(self, selector: #selector(SwiftLintXcode.onApplicationDidFinishLaunching), name: NSNotification.Name.NSApplicationDidFinishLaunching, object: nil)
center.addObserver(self, selector: #selector(SwiftLintXcode.onApplicationDidFinishLaunching), name: NSApplication.didFinishLaunchingNotification, object: nil)
}

deinit {
Expand All @@ -32,7 +32,7 @@ class SwiftLintXcode: NSObject {
center.removeObserver(self)
}

func onApplicationDidFinishLaunching() {
@objc func onApplicationDidFinishLaunching() {
SaveHook.swizzle()
createMenuItems()
}
Expand Down Expand Up @@ -66,18 +66,18 @@ class SwiftLintXcode: NSObject {
updateMenuVisibility()
}

func doAutoCorrect() {
@objc func doAutoCorrect() {
let sourceCodeDocument: IDESourceCodeDocument = SwiftLintXcodeTRVSXcode.sourceCodeDocument()
guard Formatter.isFormattableDocument(sourceCodeDocument) else { return }
Formatter.sharedInstance.tryFormatDocument(sourceCodeDocument)
}

func doEnableFormatOnSave() {
@objc func doEnableFormatOnSave() {
SaveHook.enabled = true
updateMenuVisibility()
}

func doDisableFormatOnSave() {
@objc func doDisableFormatOnSave() {
SaveHook.enabled = false
updateMenuVisibility()
}
Expand Down