Skip to content

Commit ecc8e11

Browse files
authored
Merge pull request #14 from huyphams/swift-4.1
Migrated to Swift 4.1 and fixed warnings
2 parents 97d9bc9 + 641a2ef commit ecc8e11

File tree

10 files changed

+23
-22
lines changed

10 files changed

+23
-22
lines changed

.swiftlint.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ disabled_rules:
55
- function_body_length
66
- file_length
77
- type_body_length
8-
- force_cast
9-
- force_try
10-
- legacy_nsgeometry_functions
118
- function_parameter_count
12-
- multiple_closures_with_trailing_closure
9+
- discarded_notification_center_observer
1310
- line_length
1411
- large_tuple
15-
- discarded_notification_center_observer
16-
- legacy_constructor

Demo/Demo/DetailsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DetailsView: NSView {
1919

2020
// Draw theme details image
2121
let imageSize = NSSize(width: 48, height: 48)
22-
ThemeImage.detailsImage.draw(in: NSMakeRect((bounds.width - imageSize.width) / 2, bounds.height - 56, imageSize.width, imageSize.height))
22+
ThemeImage.detailsImage.draw(in: NSRect(x: (bounds.width - imageSize.width) / 2, y: bounds.height - 56, width: imageSize.width, height: imageSize.height))
2323
}
2424

2525
}

Demo/Demo/PaperTheme.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class PaperTheme: NSObject, Theme {
4242
// darken paper image
4343
paperImage.lockFocus()
4444
NSColor.init(white: 0.0, alpha: 0.05).setFill()
45-
NSBezierPath(rect: NSMakeRect(0, 0, paperImage.size.width, paperImage.size.height)).fill()
45+
NSBezierPath(rect: NSRect(x: 0, y: 0, width: paperImage.size.width, height: paperImage.size.height)).fill()
4646
paperImage.unlockFocus()
4747

4848
_windowTitleBarActiveColor = NSColor(patternImage: paperImage)
@@ -78,7 +78,7 @@ class PaperTheme: NSObject, Theme {
7878
// lighten paper image
7979
paperImage.lockFocus()
8080
NSColor.init(white: 1.0, alpha: 0.5).setFill()
81-
NSBezierPath(rect: NSMakeRect(0, 0, paperImage.size.width, paperImage.size.height)).fill()
81+
NSBezierPath(rect: NSRect(x: 0, y: 0, width: paperImage.size.width, height: paperImage.size.height)).fill()
8282
paperImage.unlockFocus()
8383

8484
_contentBackgroundColor = NSColor(patternImage: paperImage)

Demo/Demo/TitleView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class TitleView: NSView, NSTextFieldDelegate {
6060
NSBezierPath(rect: bounds).fill()
6161

6262
// Draw gradient
63-
let gradientFrame = NSMakeRect(4, 0, bounds.width - 8, 4)
63+
let gradientFrame = NSRect(x: 4, y: 0, width: bounds.width - 8, height: 4)
6464
if let gradient = ThemeGradient.rainbowGradient {
6565
gradient.draw(in: gradientFrame, angle: 0)
6666
}

Sources/NSDictionary+UserTheme.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension NSDictionary {
8686
var rangeOffset = 0
8787
NSDictionary.varsRegExpr?.enumerateMatches(in: stringValue,
8888
options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)),
89-
range: NSMakeRange(0, stringValue.count),
89+
range: NSRange(location: 0, length: stringValue.count),
9090
using: { (match, _, _) in
9191
if let matchRange = match?.range(at: 1) {
9292
var range = matchRange
@@ -124,7 +124,7 @@ extension NSDictionary {
124124
var evaluatedObject: AnyObject? = value
125125

126126
// linear-gradient(color1, color2)
127-
if let match = NSDictionary.linearGradRegExpr?.firstMatch(in: stringValue, options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)), range: NSMakeRange(0, stringValue.count)),
127+
if let match = NSDictionary.linearGradRegExpr?.firstMatch(in: stringValue, options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)), range: NSRange(location: 0, length: stringValue.count)),
128128
match.numberOfRanges == 11 {
129129

130130
// Starting color
@@ -147,7 +147,7 @@ extension NSDictionary {
147147

148148
// rgb/rgba color
149149
if evaluatedObject is String,
150-
let match = NSDictionary.colorRegExpr?.firstMatch(in: stringValue, options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)), range: NSMakeRange(0, stringValue.count)),
150+
let match = NSDictionary.colorRegExpr?.firstMatch(in: stringValue, options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)), range: NSRange(location: 0, length: stringValue.count)),
151151
match.numberOfRanges == 5 {
152152

153153
let red = (Float(stringValue.substring(withNSRange: match.range(at: 1))) ?? 255) / 255
@@ -161,7 +161,7 @@ extension NSDictionary {
161161

162162
// pattern
163163
if evaluatedObject is String,
164-
let match = NSDictionary.patternRegExpr?.firstMatch(in: stringValue, options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)), range: NSMakeRange(0, stringValue.count)),
164+
let match = NSDictionary.patternRegExpr?.firstMatch(in: stringValue, options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)), range: NSRange(location: 0, length: stringValue.count)),
165165
match.numberOfRanges == 6 {
166166

167167
let isNamedType = stringValue.substring(withNSRange: match.range(at: 2)) == "named"
@@ -183,7 +183,7 @@ extension NSDictionary {
183183

184184
// image
185185
if evaluatedObject is String,
186-
let match = NSDictionary.imageRegExpr?.firstMatch(in: stringValue, options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)), range: NSMakeRange(0, stringValue.count)),
186+
let match = NSDictionary.imageRegExpr?.firstMatch(in: stringValue, options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)), range: NSRange(location: 0, length: stringValue.count)),
187187
match.numberOfRanges == 6 {
188188

189189
let isNamedType = stringValue.substring(withNSRange: match.range(at: 2)) == "named"

Sources/NSObject+ThemeKit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ extension NSObject {
7272
}
7373

7474
// release buffer
75-
buffer.deallocate(capacity: Int(expectedCount))
75+
buffer.deallocate()
7676

7777
return results
7878
}

Sources/NSWindow+ThemeKit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public extension NSWindow {
168168
if let screenshot = takeScreenshot(),
169169
let parentView = window.contentView {
170170
// Add image view
171-
let imageView = NSImageView(frame: NSMakeRect(0, 0, screenshot.size.width, screenshot.size.height))
171+
let imageView = NSImageView(frame: NSRect(x: 0, y: 0, width: screenshot.size.width, height: screenshot.size.height))
172172
imageView.image = screenshot
173173
parentView.addSubview(imageView)
174174
}

Sources/ThemeManager.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class ThemeManager: NSObject {
2525
/// ThemeManager shared manager.
2626
@objc(sharedManager)
2727
public static let shared = ThemeManager()
28+
private var obj: NSObjectProtocol?
2829

2930
// MARK: -
3031
// MARK: Initialization & Cleanup
@@ -36,7 +37,7 @@ public class ThemeManager: NSObject {
3637
NSColor.swizzleNSColor()
3738

3839
// Observe and theme new windows (before being displayed onscreen)
39-
NotificationCenter.default.addObserver(forName: NSWindow.didUpdateNotification, object: nil, queue: nil) { (notification) in
40+
self.obj = NotificationCenter.default.addObserver(forName: NSWindow.didUpdateNotification, object: nil, queue: nil) { (notification) in
4041
if let window = notification.object as? NSWindow {
4142
window.themeIfCompliantWithWindowThemePolicy()
4243
}
@@ -50,6 +51,9 @@ public class ThemeManager: NSObject {
5051
}
5152

5253
deinit {
54+
if let object = self.obj {
55+
NotificationCenter.default.removeObserver(object)
56+
}
5357
NSUserDefaultsController.shared.removeObserver(self, forKeyPath: themeChangeKVOKeyPath)
5458
}
5559

ThemeKit.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
286DE7BF1D92DF8F00767E00 /* Project object */ = {
185185
isa = PBXProject;
186186
attributes = {
187-
LastUpgradeCheck = 0900;
187+
LastUpgradeCheck = 0930;
188188
ORGANIZATIONNAME = "Paw Inc.";
189189
TargetAttributes = {
190190
286DE7C71D92DF8F00767E00 = {
@@ -281,13 +281,15 @@
281281
CLANG_WARN_BOOL_CONVERSION = YES;
282282
CLANG_WARN_COMMA = YES;
283283
CLANG_WARN_CONSTANT_CONVERSION = YES;
284+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
284285
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
285286
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
286287
CLANG_WARN_EMPTY_BODY = YES;
287288
CLANG_WARN_ENUM_CONVERSION = YES;
288289
CLANG_WARN_INFINITE_RECURSION = YES;
289290
CLANG_WARN_INT_CONVERSION = YES;
290291
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
292+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
291293
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
292294
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
293295
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -340,13 +342,15 @@
340342
CLANG_WARN_BOOL_CONVERSION = YES;
341343
CLANG_WARN_COMMA = YES;
342344
CLANG_WARN_CONSTANT_CONVERSION = YES;
345+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
343346
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
344347
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
345348
CLANG_WARN_EMPTY_BODY = YES;
346349
CLANG_WARN_ENUM_CONVERSION = YES;
347350
CLANG_WARN_INFINITE_RECURSION = YES;
348351
CLANG_WARN_INT_CONVERSION = YES;
349352
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
353+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
350354
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
351355
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
352356
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;

ThemeKit.xcodeproj/xcshareddata/xcschemes/ThemeKit.xcscheme

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0910"
3+
LastUpgradeVersion = "0930"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
3029
shouldUseLaunchSchemeArgsEnv = "YES">
3130
<Testables>
3231
</Testables>
@@ -37,7 +36,6 @@
3736
buildConfiguration = "Debug"
3837
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3938
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
40-
language = ""
4139
launchStyle = "0"
4240
useCustomWorkingDirectory = "NO"
4341
ignoresPersistentStateOnLaunch = "NO"

0 commit comments

Comments
 (0)