Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit f504970

Browse files
Jakob MygindJakob Mygind
authored andcommitted
Merged swift3-0 into master
2 parents db8960e + fd729a1 commit f504970

10 files changed

Lines changed: 323 additions & 87 deletions

File tree

Noted.xcodeproj/project.pbxproj

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
/* Begin PBXBuildFile section */
1010
0135E62C1C7B5A6F007982E1 /* Noted.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0135E6281C7B5A6F007982E1 /* Noted.swift */; };
1111
0135E62E1C7B5A6F007982E1 /* Noted.h in Headers */ = {isa = PBXBuildFile; fileRef = 0135E62B1C7B5A6F007982E1 /* Noted.h */; settings = {ATTRIBUTES = (Public, ); }; };
12-
017E1C801D89A56F00034114 /* TestNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017E1C7F1D89A56F00034114 /* TestNotification.swift */; };
13-
017E1C841D89A5DC00034114 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017E1C831D89A5DC00034114 /* TestObserver.swift */; };
12+
0159B06D1D8D862800467CC4 /* NoteObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0159B06C1D8D862800467CC4 /* NoteObserver.swift */; };
13+
0159B06F1D8D863900467CC4 /* NoteType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0159B06E1D8D863900467CC4 /* NoteType.swift */; };
14+
0159B0711D8D864300467CC4 /* NoteFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0159B0701D8D864300467CC4 /* NoteFilter.swift */; };
15+
017E1C871D89AE0C00034114 /* TestNote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017E1C861D89AE0C00034114 /* TestNote.swift */; };
16+
017E1C891D89AE1200034114 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017E1C881D89AE1200034114 /* TestObserver.swift */; };
1417
272F1E1D1C6A4A250098F620 /* Noted.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 272F1E121C6A4A250098F620 /* Noted.framework */; };
1518
272F1E221C6A4A250098F620 /* NotedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272F1E211C6A4A250098F620 /* NotedTests.swift */; };
1619
/* End PBXBuildFile section */
@@ -29,8 +32,11 @@
2932
0135E6281C7B5A6F007982E1 /* Noted.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Noted.swift; sourceTree = "<group>"; };
3033
0135E62A1C7B5A6F007982E1 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3134
0135E62B1C7B5A6F007982E1 /* Noted.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Noted.h; sourceTree = "<group>"; };
32-
017E1C7F1D89A56F00034114 /* TestNotification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNotification.swift; sourceTree = "<group>"; };
33-
017E1C831D89A5DC00034114 /* TestObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestObserver.swift; sourceTree = "<group>"; };
35+
0159B06C1D8D862800467CC4 /* NoteObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoteObserver.swift; sourceTree = "<group>"; };
36+
0159B06E1D8D863900467CC4 /* NoteType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoteType.swift; sourceTree = "<group>"; };
37+
0159B0701D8D864300467CC4 /* NoteFilter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoteFilter.swift; sourceTree = "<group>"; };
38+
017E1C861D89AE0C00034114 /* TestNote.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNote.swift; sourceTree = "<group>"; };
39+
017E1C881D89AE1200034114 /* TestObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestObserver.swift; sourceTree = "<group>"; };
3440
272F1E121C6A4A250098F620 /* Noted.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Noted.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3541
272F1E1C1C6A4A250098F620 /* NotedTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NotedTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3642
272F1E211C6A4A250098F620 /* NotedTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotedTests.swift; sourceTree = "<group>"; };
@@ -60,6 +66,9 @@
6066
isa = PBXGroup;
6167
children = (
6268
0135E6281C7B5A6F007982E1 /* Noted.swift */,
69+
0159B06C1D8D862800467CC4 /* NoteObserver.swift */,
70+
0159B06E1D8D863900467CC4 /* NoteType.swift */,
71+
0159B0701D8D864300467CC4 /* NoteFilter.swift */,
6372
);
6473
path = Classes;
6574
sourceTree = "<group>";
@@ -73,19 +82,12 @@
7382
path = "Supporting Files";
7483
sourceTree = "<group>";
7584
};
76-
017E1C811D89A59500034114 /* Supporting Files */ = {
77-
isa = PBXGroup;
78-
children = (
79-
272F1E231C6A4A250098F620 /* Info.plist */,
80-
);
81-
name = "Supporting Files";
82-
sourceTree = "<group>";
83-
};
84-
017E1C821D89A59D00034114 /* Test Objects */ = {
85+
86+
017E1C851D89AE0300034114 /* Test Objects */ = {
8587
isa = PBXGroup;
8688
children = (
87-
017E1C7F1D89A56F00034114 /* TestNotification.swift */,
88-
017E1C831D89A5DC00034114 /* TestObserver.swift */,
89+
017E1C861D89AE0C00034114 /* TestNote.swift */,
90+
017E1C881D89AE1200034114 /* TestObserver.swift */,
8991
);
9092
path = "Test Objects";
9193
sourceTree = "<group>";
@@ -120,9 +122,10 @@
120122
272F1E201C6A4A250098F620 /* NotedTests */ = {
121123
isa = PBXGroup;
122124
children = (
123-
017E1C821D89A59D00034114 /* Test Objects */,
125+
126+
017E1C851D89AE0300034114 /* Test Objects */,
124127
272F1E211C6A4A250098F620 /* NotedTests.swift */,
125-
017E1C811D89A59500034114 /* Supporting Files */,
128+
272F1E231C6A4A250098F620 /* Info.plist */,
126129
);
127130
path = NotedTests;
128131
sourceTree = "<group>";
@@ -184,14 +187,16 @@
184187
isa = PBXProject;
185188
attributes = {
186189
LastSwiftUpdateCheck = 0720;
187-
LastUpgradeCheck = 0730;
190+
LastUpgradeCheck = 0800;
188191
ORGANIZATIONNAME = Nodes;
189192
TargetAttributes = {
190193
272F1E111C6A4A250098F620 = {
191194
CreatedOnToolsVersion = 7.2.1;
195+
LastSwiftMigration = 0800;
192196
};
193197
272F1E1B1C6A4A250098F620 = {
194198
CreatedOnToolsVersion = 7.2.1;
199+
LastSwiftMigration = 0800;
195200
};
196201
};
197202
};
@@ -235,17 +240,20 @@
235240
isa = PBXSourcesBuildPhase;
236241
buildActionMask = 2147483647;
237242
files = (
243+
0159B06F1D8D863900467CC4 /* NoteType.swift in Sources */,
238244
0135E62C1C7B5A6F007982E1 /* Noted.swift in Sources */,
245+
0159B06D1D8D862800467CC4 /* NoteObserver.swift in Sources */,
246+
0159B0711D8D864300467CC4 /* NoteFilter.swift in Sources */,
239247
);
240248
runOnlyForDeploymentPostprocessing = 0;
241249
};
242250
272F1E181C6A4A250098F620 /* Sources */ = {
243251
isa = PBXSourcesBuildPhase;
244252
buildActionMask = 2147483647;
245253
files = (
254+
017E1C891D89AE1200034114 /* TestObserver.swift in Sources */,
246255
272F1E221C6A4A250098F620 /* NotedTests.swift in Sources */,
247-
017E1C801D89A56F00034114 /* TestNotification.swift in Sources */,
248-
017E1C841D89A5DC00034114 /* TestObserver.swift in Sources */,
256+
017E1C871D89AE0C00034114 /* TestNote.swift in Sources */,
249257
);
250258
runOnlyForDeploymentPostprocessing = 0;
251259
};
@@ -273,8 +281,10 @@
273281
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
274282
CLANG_WARN_EMPTY_BODY = YES;
275283
CLANG_WARN_ENUM_CONVERSION = YES;
284+
CLANG_WARN_INFINITE_RECURSION = YES;
276285
CLANG_WARN_INT_CONVERSION = YES;
277286
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
287+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
278288
CLANG_WARN_UNREACHABLE_CODE = YES;
279289
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
280290
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -297,7 +307,7 @@
297307
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
298308
GCC_WARN_UNUSED_FUNCTION = YES;
299309
GCC_WARN_UNUSED_VARIABLE = YES;
300-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
310+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
301311
MTL_ENABLE_DEBUG_INFO = YES;
302312
ONLY_ACTIVE_ARCH = YES;
303313
SDKROOT = iphoneos;
@@ -321,8 +331,10 @@
321331
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
322332
CLANG_WARN_EMPTY_BODY = YES;
323333
CLANG_WARN_ENUM_CONVERSION = YES;
334+
CLANG_WARN_INFINITE_RECURSION = YES;
324335
CLANG_WARN_INT_CONVERSION = YES;
325336
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
337+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
326338
CLANG_WARN_UNREACHABLE_CODE = YES;
327339
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
328340
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -339,9 +351,10 @@
339351
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
340352
GCC_WARN_UNUSED_FUNCTION = YES;
341353
GCC_WARN_UNUSED_VARIABLE = YES;
342-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
354+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
343355
MTL_ENABLE_DEBUG_INFO = NO;
344356
SDKROOT = iphoneos;
357+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
345358
TARGETED_DEVICE_FAMILY = "1,2";
346359
VALIDATE_PRODUCT = YES;
347360
VERSIONING_SYSTEM = "apple-generic";
@@ -354,17 +367,20 @@
354367
buildSettings = {
355368
APPLICATION_EXTENSION_API_ONLY = YES;
356369
CLANG_ENABLE_MODULES = YES;
370+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
357371
DEFINES_MODULE = YES;
358372
DYLIB_COMPATIBILITY_VERSION = 1;
359373
DYLIB_CURRENT_VERSION = 1;
360374
DYLIB_INSTALL_NAME_BASE = "@rpath";
361375
INFOPLIST_FILE = "$(SRCROOT)/Noted/Supporting Files/Info.plist";
362376
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
377+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
363378
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
364379
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.Noted;
365380
PRODUCT_NAME = "$(TARGET_NAME)";
366381
SKIP_INSTALL = YES;
367382
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
383+
SWIFT_VERSION = 3.0;
368384
};
369385
name = Debug;
370386
};
@@ -373,36 +389,43 @@
373389
buildSettings = {
374390
APPLICATION_EXTENSION_API_ONLY = YES;
375391
CLANG_ENABLE_MODULES = YES;
392+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
376393
DEFINES_MODULE = YES;
377394
DYLIB_COMPATIBILITY_VERSION = 1;
378395
DYLIB_CURRENT_VERSION = 1;
379396
DYLIB_INSTALL_NAME_BASE = "@rpath";
380397
INFOPLIST_FILE = "$(SRCROOT)/Noted/Supporting Files/Info.plist";
381398
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
399+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
382400
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
383401
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.Noted;
384402
PRODUCT_NAME = "$(TARGET_NAME)";
385403
SKIP_INSTALL = YES;
404+
SWIFT_VERSION = 3.0;
386405
};
387406
name = Release;
388407
};
389408
272F1E2A1C6A4A250098F620 /* Debug */ = {
390409
isa = XCBuildConfiguration;
391410
buildSettings = {
411+
CLANG_ENABLE_CODE_COVERAGE = NO;
392412
INFOPLIST_FILE = NotedTests/Info.plist;
393413
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
394414
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.NotedTests;
395415
PRODUCT_NAME = "$(TARGET_NAME)";
416+
SWIFT_VERSION = 3.0;
396417
};
397418
name = Debug;
398419
};
399420
272F1E2B1C6A4A250098F620 /* Release */ = {
400421
isa = XCBuildConfiguration;
401422
buildSettings = {
423+
CLANG_ENABLE_CODE_COVERAGE = NO;
402424
INFOPLIST_FILE = NotedTests/Info.plist;
403425
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
404426
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.NotedTests;
405427
PRODUCT_NAME = "$(TARGET_NAME)";
428+
SWIFT_VERSION = 3.0;
406429
};
407430
name = Release;
408431
};

Noted.xcodeproj/xcshareddata/xcschemes/Noted.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 = "0730"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Noted/Classes/NoteFilter.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// NoteFilter.swift
3+
// Noted
4+
//
5+
// Created by Dominik Hádl on 17/09/16.
6+
// Copyright © 2016 Nodes. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public protocol NoteFilter {
12+
func shouldFilter(note: NoteType) -> Bool
13+
}
14+
15+
internal struct PassthroughNoteFilter: NoteFilter {
16+
internal func shouldFilter(note: NoteType) -> Bool {
17+
return false
18+
}
19+
}

Noted/Classes/NoteObserver.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// NoteObserver.swift
3+
// Noted
4+
//
5+
// Created by Dominik Hádl on 17/09/16.
6+
// Copyright © 2016 Nodes. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public protocol NoteObserver: AnyObject {
12+
func didReceive(note: NoteType)
13+
var noteFilter: NoteFilter { get }
14+
}
15+
16+
extension NoteObserver {
17+
public var noteFilter: NoteFilter {
18+
return Noted.passthroughFilter
19+
}
20+
}

Noted/Classes/NoteType.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// NoteType.swift
3+
// Noted
4+
//
5+
// Created by Dominik Hádl on 17/09/16.
6+
// Copyright © 2016 Nodes. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public protocol NoteType { }

Noted/Classes/Noted.swift

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,45 @@
77

88
import Foundation
99

10-
public protocol Notification {
11-
func trigger(receiver: AnyObject)
12-
}
13-
1410
public class Noted {
1511

1612
public static let defaultInstance = Noted()
13+
14+
private let notedQueue = DispatchQueue(label: "com.nodes.noted", attributes: .concurrent)
15+
internal var _observers = NSHashTable<AnyObject>(options: .weakMemory)
1716

18-
private let notedQueue = dispatch_queue_create("com.nodes.queue", DISPATCH_QUEUE_CONCURRENT)
19-
internal var receivers = NSHashTable(options: .WeakMemory)
17+
internal static let passthroughFilter = PassthroughNoteFilter()
2018

19+
public var observers: [NoteObserver] {
20+
var values: [AnyObject] = []
21+
notedQueue.sync {
22+
values = self._observers.allObjects
23+
}
24+
return values.flatMap({ $0 as? NoteObserver })
25+
}
26+
2127
private init() {}
2228

23-
public func addObserver(observer: AnyObject) {
24-
dispatch_barrier_async(notedQueue) { [weak self] in
25-
self?.receivers.addObject(observer)
29+
public func add(observer: NoteObserver, filter: NoteFilter = PassthroughNoteFilter()) {
30+
notedQueue.async(group: nil, qos: .default, flags: .barrier) {
31+
self._observers.add(observer)
2632
}
2733
}
2834

29-
public func removeObserver(observer: AnyObject) {
30-
dispatch_barrier_async(notedQueue) { [weak self] in
31-
self?.receivers.removeObject(observer)
35+
public func remove(observer: NoteObserver) {
36+
notedQueue.async(group: nil, qos: .default, flags: .barrier) {
37+
if let foundEntry = (self._observers.allObjects).first(where: {$0 === observer}) {
38+
self._observers.remove(foundEntry)
39+
}
3240
}
3341
}
3442

35-
public func postNotification(notification: Notification) {
36-
dispatch_async(notedQueue) {
37-
for receiver in self.receivers.allObjects {
38-
dispatch_async(dispatch_get_main_queue()) {
39-
notification.trigger(receiver)
43+
44+
public func post(note: NoteType) {
45+
notedQueue.async {
46+
for receiver in self.observers.filter({ !$0.noteFilter.shouldFilter(note: note) }) {
47+
DispatchQueue.main.async {
48+
receiver.didReceive(note: note)
4049
}
4150
}
4251
}

0 commit comments

Comments
 (0)