Skip to content

Commit 1822e20

Browse files
committed
Swift 3.0
1 parent 0bcbaa3 commit 1822e20

File tree

6 files changed

+56
-54
lines changed

6 files changed

+56
-54
lines changed

Screen on Screen.xcodeproj/project.pbxproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@
103103
attributes = {
104104
LastSwiftMigration = 0720;
105105
LastSwiftUpdateCheck = 0700;
106-
LastUpgradeCheck = 0720;
106+
LastUpgradeCheck = 0800;
107107
ORGANIZATIONNAME = "Shandong University";
108108
TargetAttributes = {
109109
E2E48A501B1E96E70023D48D = {
110110
CreatedOnToolsVersion = 6.3.2;
111111
DevelopmentTeam = 5Z4L8A2TF8;
112+
LastSwiftMigration = 0800;
112113
SystemCapabilities = {
113114
com.apple.Sandbox = {
114115
enabled = 1;
@@ -177,6 +178,7 @@
177178
isa = XCBuildConfiguration;
178179
buildSettings = {
179180
ALWAYS_SEARCH_USER_PATHS = NO;
181+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
180182
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
181183
CLANG_CXX_LIBRARY = "libc++";
182184
CLANG_ENABLE_MODULES = YES;
@@ -186,8 +188,10 @@
186188
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
187189
CLANG_WARN_EMPTY_BODY = YES;
188190
CLANG_WARN_ENUM_CONVERSION = YES;
191+
CLANG_WARN_INFINITE_RECURSION = YES;
189192
CLANG_WARN_INT_CONVERSION = YES;
190193
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
194+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
191195
CLANG_WARN_UNREACHABLE_CODE = YES;
192196
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
193197
CODE_SIGN_IDENTITY = "-";
@@ -220,6 +224,7 @@
220224
isa = XCBuildConfiguration;
221225
buildSettings = {
222226
ALWAYS_SEARCH_USER_PATHS = NO;
227+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
223228
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
224229
CLANG_CXX_LIBRARY = "libc++";
225230
CLANG_ENABLE_MODULES = YES;
@@ -229,8 +234,10 @@
229234
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
230235
CLANG_WARN_EMPTY_BODY = YES;
231236
CLANG_WARN_ENUM_CONVERSION = YES;
237+
CLANG_WARN_INFINITE_RECURSION = YES;
232238
CLANG_WARN_INT_CONVERSION = YES;
233239
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
240+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
234241
CLANG_WARN_UNREACHABLE_CODE = YES;
235242
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
236243
CODE_SIGN_IDENTITY = "-";
@@ -263,6 +270,7 @@
263270
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
264271
PRODUCT_BUNDLE_IDENTIFIER = "cn.edu.sdu.$(PRODUCT_NAME:rfc1034identifier)";
265272
PRODUCT_NAME = "Screen on Screen";
273+
SWIFT_VERSION = 3.0;
266274
};
267275
name = Debug;
268276
};
@@ -277,6 +285,7 @@
277285
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
278286
PRODUCT_BUNDLE_IDENTIFIER = "cn.edu.sdu.$(PRODUCT_NAME:rfc1034identifier)";
279287
PRODUCT_NAME = "Screen on Screen";
288+
SWIFT_VERSION = 3.0;
280289
};
281290
name = Release;
282291
};

Screen on Screen.xcodeproj/xcuserdata/cc941201.xcuserdatad/xcschemes/Screen on Screen.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0720"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Screen on Screen/AppDelegate.swift

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,36 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1414
@IBOutlet weak var zoomMenu: NSMenu!
1515
@IBOutlet weak var onTopMenuItem: NSMenuItem!
1616

17-
private let notificationCenter = NSNotificationCenter.defaultCenter()
18-
19-
func applicationDidFinishLaunching(notification: NSNotification) {
17+
func applicationDidFinishLaunching(_ notification: Notification) {
2018
updateDisplays()
2119
updateZoom()
22-
notificationCenter.addObserverForName(Utility.Notification.ScaleChange, object: nil, queue: nil) { _ in
20+
NotificationCenter.default.addObserver(forName: .scaleChange, object: nil, queue: nil) { _ in
2321
self.updateZoom()
2422
}
2523
if Utility.onTop {
2624
onTopMenuItem.state = NSOnState
2725
}
2826
}
2927

30-
func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool {
28+
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
3129
return true
3230
}
3331

34-
func applicationDidChangeScreenParameters(notification: NSNotification) {
32+
func applicationDidChangeScreenParameters(_ notification: Notification) {
3533
updateDisplays()
3634
}
3735

38-
func display(sender: NSMenuItem) {
39-
screenMenu.itemAtIndex(Utility.displayNo)?.state = NSOffState
36+
func display(_ sender: NSMenuItem) {
37+
screenMenu.item(at: Utility.displayNo)?.state = NSOffState
4038
Utility.displayNo = sender.tag
41-
screenMenu.itemAtIndex(Utility.displayNo)?.state = NSOnState
39+
screenMenu.item(at: Utility.displayNo)?.state = NSOnState
4240
}
4341

44-
@IBAction func zoom(sender: NSMenuItem) {
42+
@IBAction func zoom(_ sender: NSMenuItem) {
4543
Utility.scale = Double(sender.tag) / 100
4644
}
4745

48-
@IBAction func top(sender: NSMenuItem) {
46+
@IBAction func top(_ sender: NSMenuItem) {
4947
if sender.state == NSOffState {
5048
Utility.onTop = true
5149
sender.state = NSOnState
@@ -70,20 +68,20 @@ class AppDelegate: NSObject, NSApplicationDelegate {
7068
}
7169

7270
func updateZoom() {
73-
for item in zoomMenu.itemArray {
71+
for item in zoomMenu.items {
7472
item.state = NSOffState
7573
}
7674
switch Utility.scale {
7775
case 1:
78-
zoomMenu.itemAtIndex(0)!.state = NSOnState
76+
zoomMenu.item(at: 0)!.state = NSOnState
7977
case 0.75:
80-
zoomMenu.itemAtIndex(1)!.state = NSOnState
78+
zoomMenu.item(at: 1)!.state = NSOnState
8179
case 0.5:
82-
zoomMenu.itemAtIndex(2)!.state = NSOnState
80+
zoomMenu.item(at: 2)!.state = NSOnState
8381
case 0.33:
84-
zoomMenu.itemAtIndex(3)!.state = NSOnState
82+
zoomMenu.item(at: 3)!.state = NSOnState
8583
case 0.25:
86-
zoomMenu.itemAtIndex(4)!.state = NSOnState
84+
zoomMenu.item(at: 4)!.state = NSOnState
8785
default: break
8886
}
8987
}

Screen on Screen/Base.lproj/Main.storyboard

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
55
</dependencies>
66
<scenes>
77
<!--Application-->

Screen on Screen/Utility.swift

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ struct Utility {
1313

1414
static var displayNo: Int {
1515
get {
16-
let displayNo = userDefaults.integerForKey(Keys.Display)
16+
let displayNo = UserDefaults.standard.integer(forKey: Keys.display)
1717
if displayNo >= displays.count {
1818
return displays.count > 1 ? 1 : 0
1919
}
2020
return displayNo
2121
}
2222
set {
23-
userDefaults.setInteger(newValue, forKey: Keys.Display)
24-
notificationCenter.postNotificationName(Notification.DisplayChange, object: nil)
23+
UserDefaults.standard.set(newValue, forKey: Keys.display)
24+
NotificationCenter.default.post(name: .displayChange, object: nil)
2525
}
2626
}
2727

@@ -31,47 +31,44 @@ struct Utility {
3131

3232
static var scale: Double {
3333
get {
34-
let scale = userDefaults.doubleForKey(Keys.Scale)
34+
let scale = UserDefaults.standard.double(forKey: Keys.scale)
3535
return scale == 0 ? 0.5 : scale
3636
}
3737
set {
38-
userDefaults.setDouble(newValue, forKey: Keys.Scale)
39-
notificationCenter.postNotificationName(Notification.ScaleChange, object: nil)
38+
UserDefaults.standard.set(newValue, forKey: Keys.scale)
39+
NotificationCenter.default.post(name: .scaleChange, object: nil)
4040
}
4141
}
4242

4343
static var onTop: Bool {
4444
get {
45-
return userDefaults.boolForKey(Keys.OnTop)
45+
return UserDefaults.standard.bool(forKey: Keys.onTop)
4646
}
4747
set {
48-
userDefaults.setBool(newValue, forKey: Keys.OnTop)
49-
notificationCenter.postNotificationName(Notification.OnTopChange, object: nil)
48+
UserDefaults.standard.set(newValue, forKey: Keys.onTop)
49+
NotificationCenter.default.post(name: .onTopChange, object: nil)
5050
}
5151
}
5252

53-
private static let userDefaults = NSUserDefaults.standardUserDefaults()
54-
private static let notificationCenter = NSNotificationCenter.defaultCenter()
55-
5653
static func updateDisplays() {
5754
let screens = NSScreen.screens() ?? []
58-
displays = screens.map { ($0.deviceDescription["NSScreenNumber"] as! NSNumber).unsignedIntValue }
55+
displays = screens.map { ($0.deviceDescription["NSScreenNumber"] as! NSNumber).uint32Value }
5956
if displays.count > 1 && displayNo == 0 {
6057
displayNo = 1
6158
} else {
62-
notificationCenter.postNotificationName(Notification.DisplayChange, object: nil)
59+
NotificationCenter.default.post(name: .displayChange, object: nil)
6360
}
6461
}
6562

6663
private struct Keys {
67-
static let Display = "Display"
68-
static let Scale = "Scale"
69-
static let OnTop = "OnTop"
70-
}
71-
72-
struct Notification {
73-
static let DisplayChange = "DisplayChange"
74-
static let ScaleChange = "ScaleChange"
75-
static let OnTopChange = "OnTopChange"
64+
static let display = "Display"
65+
static let scale = "Scale"
66+
static let onTop = "OnTop"
7667
}
7768
}
69+
70+
extension Notification.Name {
71+
static let displayChange = Notification.Name("DisplayChange")
72+
static let scaleChange = Notification.Name("ScaleChange")
73+
static let onTopChange = Notification.Name("OnTopChange")
74+
}

Screen on Screen/ViewController.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,24 @@ class ViewController: NSViewController {
5353
}
5454
}
5555

56-
private let notificationCenter = NSNotificationCenter.defaultCenter()
57-
5856
override func viewWillAppear() {
5957
super.viewWillAppear()
60-
view.window!.movableByWindowBackground = true
61-
view.layer!.backgroundColor = NSColor.blackColor().CGColor
62-
notificationCenter.addObserverForName(Utility.Notification.DisplayChange, object: nil, queue: nil) { _ in
58+
view.window!.isMovableByWindowBackground = true
59+
view.layer!.backgroundColor = NSColor.black.cgColor
60+
NotificationCenter.default.addObserver(forName: .displayChange, object: nil, queue: nil) { _ in
6361
if self.displayID != Utility.displayID {
6462
self.displayID = Utility.displayID
6563
}
6664
self.updateSize()
6765
}
68-
notificationCenter.addObserverForName(Utility.Notification.ScaleChange, object: nil, queue: nil) { _ in
66+
NotificationCenter.default.addObserver(forName: .scaleChange, object: nil, queue: nil) { _ in
6967
self.updateSize()
7068
}
7169
if Utility.onTop {
72-
view.window!.level = Int(CGWindowLevelForKey(.FloatingWindowLevelKey))
70+
view.window!.level = Int(CGWindowLevelForKey(.floatingWindow))
7371
}
74-
notificationCenter.addObserverForName(Utility.Notification.OnTopChange, object: nil, queue: nil) { _ in
75-
self.view.window!.level = Int(CGWindowLevelForKey(Utility.onTop ? .FloatingWindowLevelKey : .NormalWindowLevelKey))
72+
NotificationCenter.default.addObserver(forName: .onTopChange, object: nil, queue: nil) { _ in
73+
self.view.window!.level = Int(CGWindowLevelForKey(Utility.onTop ? .floatingWindow : .normalWindow))
7674
}
7775
}
7876

@@ -89,7 +87,7 @@ class ViewController: NSViewController {
8987
}
9088
}
9189

92-
@IBAction func scale(sender: NSMagnificationGestureRecognizer) {
90+
@IBAction func scale(_ sender: NSMagnificationGestureRecognizer) {
9391
Utility.scale += Double(sender.magnification) / 50
9492
}
9593
}

0 commit comments

Comments
 (0)