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

Commit

Permalink
Merged swift3-0 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Mygind authored and Jakob Mygind committed Sep 19, 2016
2 parents db8960e + fd729a1 commit f504970
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 87 deletions.
67 changes: 45 additions & 22 deletions Noted.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
/* 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, ); }; };
017E1C801D89A56F00034114 /* TestNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017E1C7F1D89A56F00034114 /* TestNotification.swift */; };
017E1C841D89A5DC00034114 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017E1C831D89A5DC00034114 /* TestObserver.swift */; };
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 */; };
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 @@ -29,8 +32,11 @@
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>"; };
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>"; };
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>"; };
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 @@ -60,6 +66,9 @@
isa = PBXGroup;
children = (
0135E6281C7B5A6F007982E1 /* Noted.swift */,
0159B06C1D8D862800467CC4 /* NoteObserver.swift */,
0159B06E1D8D863900467CC4 /* NoteType.swift */,
0159B0701D8D864300467CC4 /* NoteFilter.swift */,
);
path = Classes;
sourceTree = "<group>";
Expand All @@ -73,19 +82,12 @@
path = "Supporting Files";
sourceTree = "<group>";
};
017E1C811D89A59500034114 /* Supporting Files */ = {
isa = PBXGroup;
children = (
272F1E231C6A4A250098F620 /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
017E1C821D89A59D00034114 /* Test Objects */ = {

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

017E1C851D89AE0300034114 /* Test Objects */,
272F1E211C6A4A250098F620 /* NotedTests.swift */,
017E1C811D89A59500034114 /* Supporting Files */,
272F1E231C6A4A250098F620 /* Info.plist */,
);
path = NotedTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -184,14 +187,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Nodes;
TargetAttributes = {
272F1E111C6A4A250098F620 = {
CreatedOnToolsVersion = 7.2.1;
LastSwiftMigration = 0800;
};
272F1E1B1C6A4A250098F620 = {
CreatedOnToolsVersion = 7.2.1;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -235,17 +240,20 @@
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 */,
017E1C801D89A56F00034114 /* TestNotification.swift in Sources */,
017E1C841D89A5DC00034114 /* TestObserver.swift in Sources */,
017E1C871D89AE0C00034114 /* TestNote.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -273,8 +281,10 @@
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 @@ -297,7 +307,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -321,8 +331,10 @@
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 @@ -339,9 +351,10 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.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 @@ -354,17 +367,20 @@
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;
};
name = Debug;
};
Expand All @@ -373,36 +389,43 @@
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;
};
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;
};
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;
};
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 = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
19 changes: 19 additions & 0 deletions Noted/Classes/NoteFilter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// NoteFilter.swift
// Noted
//
// Created by Dominik Hádl on 17/09/16.
// Copyright © 2016 Nodes. All rights reserved.
//

import Foundation

public protocol NoteFilter {
func shouldFilter(note: NoteType) -> Bool
}

internal struct PassthroughNoteFilter: NoteFilter {
internal func shouldFilter(note: NoteType) -> Bool {
return false
}
}
20 changes: 20 additions & 0 deletions Noted/Classes/NoteObserver.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// NoteObserver.swift
// Noted
//
// Created by Dominik Hádl on 17/09/16.
// Copyright © 2016 Nodes. All rights reserved.
//

import Foundation

public protocol NoteObserver: AnyObject {
func didReceive(note: NoteType)
var noteFilter: NoteFilter { get }
}

extension NoteObserver {
public var noteFilter: NoteFilter {
return Noted.passthroughFilter
}
}
11 changes: 11 additions & 0 deletions Noted/Classes/NoteType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// NoteType.swift
// Noted
//
// Created by Dominik Hádl on 17/09/16.
// Copyright © 2016 Nodes. All rights reserved.
//

import Foundation

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

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)

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

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

private init() {}

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

public func removeObserver(observer: AnyObject) {
dispatch_barrier_async(notedQueue) { [weak self] in
self?.receivers.removeObject(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 postNotification(notification: Notification) {
dispatch_async(notedQueue) {
for receiver in self.receivers.allObjects {
dispatch_async(dispatch_get_main_queue()) {
notification.trigger(receiver)

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)
}
}
}
Expand Down
Loading

0 comments on commit f504970

Please sign in to comment.