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

Commit

Permalink
Swift 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Combs committed Sep 20, 2016
1 parent cd2ab26 commit 5a3dc4d
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 319 deletions.
69 changes: 26 additions & 43 deletions Noted.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
/* Begin PBXBuildFile section */
0135E62C1C7B5A6F007982E1 /* Noted.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0135E6281C7B5A6F007982E1 /* Noted.swift */; };
0135E62E1C7B5A6F007982E1 /* Noted.h in Headers */ = {isa = PBXBuildFile; fileRef = 0135E62B1C7B5A6F007982E1 /* Noted.h */; settings = {ATTRIBUTES = (Public, ); }; };
0159B06D1D8D862800467CC4 /* NoteObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0159B06C1D8D862800467CC4 /* NoteObserver.swift */; };
0159B06F1D8D863900467CC4 /* NoteType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0159B06E1D8D863900467CC4 /* NoteType.swift */; };
0159B0711D8D864300467CC4 /* NoteFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0159B0701D8D864300467CC4 /* NoteFilter.swift */; };
017E1C871D89AE0C00034114 /* TestNote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017E1C861D89AE0C00034114 /* TestNote.swift */; };
017E1C891D89AE1200034114 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017E1C881D89AE1200034114 /* TestObserver.swift */; };
017E1C801D89A56F00034114 /* TestNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017E1C7F1D89A56F00034114 /* TestNotification.swift */; };
017E1C841D89A5DC00034114 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017E1C831D89A5DC00034114 /* TestObserver.swift */; };
272F1E1D1C6A4A250098F620 /* Noted.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 272F1E121C6A4A250098F620 /* Noted.framework */; };
272F1E221C6A4A250098F620 /* NotedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272F1E211C6A4A250098F620 /* NotedTests.swift */; };
/* End PBXBuildFile section */
Expand All @@ -32,11 +29,8 @@
0135E6281C7B5A6F007982E1 /* Noted.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Noted.swift; sourceTree = "<group>"; };
0135E62A1C7B5A6F007982E1 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0135E62B1C7B5A6F007982E1 /* Noted.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Noted.h; sourceTree = "<group>"; };
0159B06C1D8D862800467CC4 /* NoteObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoteObserver.swift; sourceTree = "<group>"; };
0159B06E1D8D863900467CC4 /* NoteType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoteType.swift; sourceTree = "<group>"; };
0159B0701D8D864300467CC4 /* NoteFilter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoteFilter.swift; sourceTree = "<group>"; };
017E1C861D89AE0C00034114 /* TestNote.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNote.swift; sourceTree = "<group>"; };
017E1C881D89AE1200034114 /* TestObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestObserver.swift; sourceTree = "<group>"; };
017E1C7F1D89A56F00034114 /* TestNotification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNotification.swift; sourceTree = "<group>"; };
017E1C831D89A5DC00034114 /* TestObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestObserver.swift; sourceTree = "<group>"; };
272F1E121C6A4A250098F620 /* Noted.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Noted.framework; sourceTree = BUILT_PRODUCTS_DIR; };
272F1E1C1C6A4A250098F620 /* NotedTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NotedTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
272F1E211C6A4A250098F620 /* NotedTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotedTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -66,9 +60,6 @@
isa = PBXGroup;
children = (
0135E6281C7B5A6F007982E1 /* Noted.swift */,
0159B06C1D8D862800467CC4 /* NoteObserver.swift */,
0159B06E1D8D863900467CC4 /* NoteType.swift */,
0159B0701D8D864300467CC4 /* NoteFilter.swift */,
);
path = Classes;
sourceTree = "<group>";
Expand All @@ -82,12 +73,19 @@
path = "Supporting Files";
sourceTree = "<group>";
};

017E1C851D89AE0300034114 /* Test Objects */ = {
017E1C811D89A59500034114 /* Supporting Files */ = {
isa = PBXGroup;
children = (
017E1C861D89AE0C00034114 /* TestNote.swift */,
017E1C881D89AE1200034114 /* TestObserver.swift */,
272F1E231C6A4A250098F620 /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
017E1C821D89A59D00034114 /* Test Objects */ = {
isa = PBXGroup;
children = (
017E1C7F1D89A56F00034114 /* TestNotification.swift */,
017E1C831D89A5DC00034114 /* TestObserver.swift */,
);
path = "Test Objects";
sourceTree = "<group>";
Expand Down Expand Up @@ -122,10 +120,9 @@
272F1E201C6A4A250098F620 /* NotedTests */ = {
isa = PBXGroup;
children = (

017E1C851D89AE0300034114 /* Test Objects */,
017E1C821D89A59D00034114 /* Test Objects */,
272F1E211C6A4A250098F620 /* NotedTests.swift */,
272F1E231C6A4A250098F620 /* Info.plist */,
017E1C811D89A59500034114 /* Supporting Files */,
);
path = NotedTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -187,7 +184,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = Nodes;
TargetAttributes = {
272F1E111C6A4A250098F620 = {
Expand Down Expand Up @@ -240,20 +237,17 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0159B06F1D8D863900467CC4 /* NoteType.swift in Sources */,
0135E62C1C7B5A6F007982E1 /* Noted.swift in Sources */,
0159B06D1D8D862800467CC4 /* NoteObserver.swift in Sources */,
0159B0711D8D864300467CC4 /* NoteFilter.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
272F1E181C6A4A250098F620 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
017E1C891D89AE1200034114 /* TestObserver.swift in Sources */,
272F1E221C6A4A250098F620 /* NotedTests.swift in Sources */,
017E1C871D89AE0C00034114 /* TestNote.swift in Sources */,
017E1C801D89A56F00034114 /* TestNotification.swift in Sources */,
017E1C841D89A5DC00034114 /* TestObserver.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -281,10 +275,8 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -307,7 +299,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -331,10 +323,8 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -351,10 +341,9 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -367,20 +356,18 @@
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "$(SRCROOT)/Noted/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.Noted;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 2.3;
};
name = Debug;
};
Expand All @@ -389,43 +376,39 @@
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "$(SRCROOT)/Noted/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.Noted;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 2.3;
};
name = Release;
};
272F1E2A1C6A4A250098F620 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_CODE_COVERAGE = NO;
INFOPLIST_FILE = NotedTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.NotedTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 2.3;
};
name = Debug;
};
272F1E2B1C6A4A250098F620 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_CODE_COVERAGE = NO;
INFOPLIST_FILE = NotedTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.NotedTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 2.3;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Noted.xcodeproj/xcshareddata/xcschemes/Noted.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
19 changes: 0 additions & 19 deletions Noted/Classes/NoteFilter.swift

This file was deleted.

20 changes: 0 additions & 20 deletions Noted/Classes/NoteObserver.swift

This file was deleted.

11 changes: 0 additions & 11 deletions Noted/Classes/NoteType.swift

This file was deleted.

43 changes: 17 additions & 26 deletions Noted/Classes/Noted.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,36 @@

import Foundation

public protocol Notification {
func trigger(receiver: AnyObject)
}

public class Noted {

public static let defaultInstance = Noted()

private let notedQueue = DispatchQueue(label: "com.nodes.noted", attributes: .concurrent)
internal var _observers = NSHashTable<AnyObject>(options: .weakMemory)

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

public var observers: [NoteObserver] {
var values: [AnyObject] = []
notedQueue.sync {
values = self._observers.allObjects
}
return values.flatMap({ $0 as? NoteObserver })
}

private init() {}

public func add(observer: NoteObserver, filter: NoteFilter = PassthroughNoteFilter()) {
notedQueue.async(group: nil, qos: .default, flags: .barrier) {
self._observers.add(observer)
public func addObserver(observer: AnyObject) {
dispatch_barrier_async(notedQueue) { [weak self] in
self?.receivers.addObject(observer)
}
}

public func remove(observer: NoteObserver) {
notedQueue.async(group: nil, qos: .default, flags: .barrier) {
if let foundEntry = (self._observers.allObjects).first(where: {$0 === observer}) {
self._observers.remove(foundEntry)
}
public func removeObserver(observer: AnyObject) {
dispatch_barrier_async(notedQueue) { [weak self] in
self?.receivers.removeObject(observer)
}
}


public func post(note: NoteType) {
notedQueue.async {
for receiver in self.observers.filter({ !$0.noteFilter.shouldFilter(note: note) }) {
DispatchQueue.main.async {
receiver.didReceive(note: note)
public func postNotification(notification: Notification) {
dispatch_async(notedQueue) {
for receiver in self.receivers.allObjects {
dispatch_async(dispatch_get_main_queue()) {
notification.trigger(receiver)
}
}
}
Expand Down
Loading

0 comments on commit 5a3dc4d

Please sign in to comment.