├── .gitignore ├── LICENSE ├── Notifwift.podspec ├── Notifwift.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ └── Notifwift.xcscheme ├── Notifwift ├── Info.plist └── Notifwift.swift ├── NotifwiftTests ├── Info.plist └── NotifwiftTests.swift ├── Package.swift └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ### https://raw.github.com/github/gitignore/be3333655bffe9507d66cc864aee95ed6052b4ed/Swift.gitignore 2 | 3 | # Xcode 4 | # 5 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 6 | 7 | ## Build generated 8 | build/ 9 | DerivedData 10 | 11 | ## Various settings 12 | *.pbxuser 13 | !default.pbxuser 14 | *.mode1v3 15 | !default.mode1v3 16 | *.mode2v3 17 | !default.mode2v3 18 | *.perspectivev3 19 | !default.perspectivev3 20 | xcuserdata 21 | 22 | ## Other 23 | *.xccheckout 24 | *.moved-aside 25 | *.xcuserstate 26 | *.xcscmblueprint 27 | 28 | ## Obj-C/Swift specific 29 | *.hmap 30 | *.ipa 31 | 32 | # Swift Package Manager 33 | # 34 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 35 | # Packages/ 36 | .build/ 37 | 38 | # CocoaPods 39 | # 40 | # We recommend against adding the Pods directory to your .gitignore. However 41 | # you should judge for yourself, the pros and cons are mentioned at: 42 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 43 | # 44 | # Pods/ 45 | 46 | # Carthage 47 | # 48 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 49 | # Carthage/Checkouts 50 | 51 | Carthage/Build 52 | 53 | # fastlane 54 | # 55 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 56 | # screenshots whenever they are needed. 57 | # For more information about the recommended setup visit: 58 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 59 | 60 | fastlane/report.xml 61 | fastlane/screenshots 62 | 63 | 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 takasek 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Notifwift.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "Notifwift" 3 | s.version = "1.1.1" 4 | s.summary = "NSNotificationCenter wrapper for Swift" 5 | s.license = 'MIT' 6 | s.homepage = "https://github.com/takasek/Notifwift" 7 | s.author = { "takasek" => "takassekiyoshi@gmail.com" } 8 | s.source = { :git => "https://github.com/takasek/Notifwift.git", 9 | :tag => s.version.to_s } 10 | s.source_files = "Sources/*.swift" 11 | s.swift_version = "4.2" 12 | s.requires_arc = true 13 | 14 | s.ios.deployment_target = "8.0" 15 | s.source_files = 'Notifwift/*.swift' 16 | end 17 | -------------------------------------------------------------------------------- /Notifwift.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B60EF8B31C671A3E00FC0BBC /* Notifwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B60EF8A81C671A3E00FC0BBC /* Notifwift.framework */; }; 11 | B60EF8B81C671A3E00FC0BBC /* NotifwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B60EF8B71C671A3E00FC0BBC /* NotifwiftTests.swift */; }; 12 | B60EF8C31C671A8D00FC0BBC /* Notifwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = B60EF8C21C671A8D00FC0BBC /* Notifwift.swift */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXContainerItemProxy section */ 16 | B60EF8B41C671A3E00FC0BBC /* PBXContainerItemProxy */ = { 17 | isa = PBXContainerItemProxy; 18 | containerPortal = B60EF89F1C671A3E00FC0BBC /* Project object */; 19 | proxyType = 1; 20 | remoteGlobalIDString = B60EF8A71C671A3E00FC0BBC; 21 | remoteInfo = Notifwift; 22 | }; 23 | /* End PBXContainerItemProxy section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 82964C4F22FAB2B600D64A33 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; 27 | B60EF8A81C671A3E00FC0BBC /* Notifwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Notifwift.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | B60EF8AD1C671A3E00FC0BBC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | B60EF8B21C671A3E00FC0BBC /* NotifwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NotifwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | B60EF8B71C671A3E00FC0BBC /* NotifwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotifwiftTests.swift; sourceTree = ""; }; 31 | B60EF8B91C671A3E00FC0BBC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | B60EF8C21C671A8D00FC0BBC /* Notifwift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Notifwift.swift; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | B60EF8A41C671A3E00FC0BBC /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | B60EF8AF1C671A3E00FC0BBC /* Frameworks */ = { 44 | isa = PBXFrameworksBuildPhase; 45 | buildActionMask = 2147483647; 46 | files = ( 47 | B60EF8B31C671A3E00FC0BBC /* Notifwift.framework in Frameworks */, 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | B60EF89E1C671A3E00FC0BBC = { 55 | isa = PBXGroup; 56 | children = ( 57 | 82964C4F22FAB2B600D64A33 /* Package.swift */, 58 | B60EF8AA1C671A3E00FC0BBC /* Notifwift */, 59 | B60EF8B61C671A3E00FC0BBC /* NotifwiftTests */, 60 | B60EF8A91C671A3E00FC0BBC /* Products */, 61 | ); 62 | sourceTree = ""; 63 | }; 64 | B60EF8A91C671A3E00FC0BBC /* Products */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | B60EF8A81C671A3E00FC0BBC /* Notifwift.framework */, 68 | B60EF8B21C671A3E00FC0BBC /* NotifwiftTests.xctest */, 69 | ); 70 | name = Products; 71 | sourceTree = ""; 72 | }; 73 | B60EF8AA1C671A3E00FC0BBC /* Notifwift */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | B60EF8AD1C671A3E00FC0BBC /* Info.plist */, 77 | B60EF8C21C671A8D00FC0BBC /* Notifwift.swift */, 78 | ); 79 | path = Notifwift; 80 | sourceTree = ""; 81 | }; 82 | B60EF8B61C671A3E00FC0BBC /* NotifwiftTests */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | B60EF8B71C671A3E00FC0BBC /* NotifwiftTests.swift */, 86 | B60EF8B91C671A3E00FC0BBC /* Info.plist */, 87 | ); 88 | path = NotifwiftTests; 89 | sourceTree = ""; 90 | }; 91 | /* End PBXGroup section */ 92 | 93 | /* Begin PBXHeadersBuildPhase section */ 94 | B60EF8A51C671A3E00FC0BBC /* Headers */ = { 95 | isa = PBXHeadersBuildPhase; 96 | buildActionMask = 2147483647; 97 | files = ( 98 | ); 99 | runOnlyForDeploymentPostprocessing = 0; 100 | }; 101 | /* End PBXHeadersBuildPhase section */ 102 | 103 | /* Begin PBXNativeTarget section */ 104 | B60EF8A71C671A3E00FC0BBC /* Notifwift */ = { 105 | isa = PBXNativeTarget; 106 | buildConfigurationList = B60EF8BC1C671A3E00FC0BBC /* Build configuration list for PBXNativeTarget "Notifwift" */; 107 | buildPhases = ( 108 | B60EF8A31C671A3E00FC0BBC /* Sources */, 109 | B60EF8A41C671A3E00FC0BBC /* Frameworks */, 110 | B60EF8A51C671A3E00FC0BBC /* Headers */, 111 | B60EF8A61C671A3E00FC0BBC /* Resources */, 112 | ); 113 | buildRules = ( 114 | ); 115 | dependencies = ( 116 | ); 117 | name = Notifwift; 118 | productName = Notifwift; 119 | productReference = B60EF8A81C671A3E00FC0BBC /* Notifwift.framework */; 120 | productType = "com.apple.product-type.framework"; 121 | }; 122 | B60EF8B11C671A3E00FC0BBC /* NotifwiftTests */ = { 123 | isa = PBXNativeTarget; 124 | buildConfigurationList = B60EF8BF1C671A3E00FC0BBC /* Build configuration list for PBXNativeTarget "NotifwiftTests" */; 125 | buildPhases = ( 126 | B60EF8AE1C671A3E00FC0BBC /* Sources */, 127 | B60EF8AF1C671A3E00FC0BBC /* Frameworks */, 128 | B60EF8B01C671A3E00FC0BBC /* Resources */, 129 | ); 130 | buildRules = ( 131 | ); 132 | dependencies = ( 133 | B60EF8B51C671A3E00FC0BBC /* PBXTargetDependency */, 134 | ); 135 | name = NotifwiftTests; 136 | productName = NotifwiftTests; 137 | productReference = B60EF8B21C671A3E00FC0BBC /* NotifwiftTests.xctest */; 138 | productType = "com.apple.product-type.bundle.unit-test"; 139 | }; 140 | /* End PBXNativeTarget section */ 141 | 142 | /* Begin PBXProject section */ 143 | B60EF89F1C671A3E00FC0BBC /* Project object */ = { 144 | isa = PBXProject; 145 | attributes = { 146 | LastSwiftUpdateCheck = 0720; 147 | LastUpgradeCheck = 1020; 148 | ORGANIZATIONNAME = "Yoshitaka Seki"; 149 | TargetAttributes = { 150 | B60EF8A71C671A3E00FC0BBC = { 151 | CreatedOnToolsVersion = 7.2; 152 | LastSwiftMigration = 0800; 153 | }; 154 | B60EF8B11C671A3E00FC0BBC = { 155 | CreatedOnToolsVersion = 7.2; 156 | LastSwiftMigration = 0800; 157 | }; 158 | }; 159 | }; 160 | buildConfigurationList = B60EF8A21C671A3E00FC0BBC /* Build configuration list for PBXProject "Notifwift" */; 161 | compatibilityVersion = "Xcode 3.2"; 162 | developmentRegion = en; 163 | hasScannedForEncodings = 0; 164 | knownRegions = ( 165 | en, 166 | Base, 167 | ); 168 | mainGroup = B60EF89E1C671A3E00FC0BBC; 169 | productRefGroup = B60EF8A91C671A3E00FC0BBC /* Products */; 170 | projectDirPath = ""; 171 | projectRoot = ""; 172 | targets = ( 173 | B60EF8A71C671A3E00FC0BBC /* Notifwift */, 174 | B60EF8B11C671A3E00FC0BBC /* NotifwiftTests */, 175 | ); 176 | }; 177 | /* End PBXProject section */ 178 | 179 | /* Begin PBXResourcesBuildPhase section */ 180 | B60EF8A61C671A3E00FC0BBC /* Resources */ = { 181 | isa = PBXResourcesBuildPhase; 182 | buildActionMask = 2147483647; 183 | files = ( 184 | ); 185 | runOnlyForDeploymentPostprocessing = 0; 186 | }; 187 | B60EF8B01C671A3E00FC0BBC /* Resources */ = { 188 | isa = PBXResourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | ); 192 | runOnlyForDeploymentPostprocessing = 0; 193 | }; 194 | /* End PBXResourcesBuildPhase section */ 195 | 196 | /* Begin PBXSourcesBuildPhase section */ 197 | B60EF8A31C671A3E00FC0BBC /* Sources */ = { 198 | isa = PBXSourcesBuildPhase; 199 | buildActionMask = 2147483647; 200 | files = ( 201 | B60EF8C31C671A8D00FC0BBC /* Notifwift.swift in Sources */, 202 | ); 203 | runOnlyForDeploymentPostprocessing = 0; 204 | }; 205 | B60EF8AE1C671A3E00FC0BBC /* Sources */ = { 206 | isa = PBXSourcesBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | B60EF8B81C671A3E00FC0BBC /* NotifwiftTests.swift in Sources */, 210 | ); 211 | runOnlyForDeploymentPostprocessing = 0; 212 | }; 213 | /* End PBXSourcesBuildPhase section */ 214 | 215 | /* Begin PBXTargetDependency section */ 216 | B60EF8B51C671A3E00FC0BBC /* PBXTargetDependency */ = { 217 | isa = PBXTargetDependency; 218 | target = B60EF8A71C671A3E00FC0BBC /* Notifwift */; 219 | targetProxy = B60EF8B41C671A3E00FC0BBC /* PBXContainerItemProxy */; 220 | }; 221 | /* End PBXTargetDependency section */ 222 | 223 | /* Begin XCBuildConfiguration section */ 224 | B60EF8BA1C671A3E00FC0BBC /* Debug */ = { 225 | isa = XCBuildConfiguration; 226 | buildSettings = { 227 | ALWAYS_SEARCH_USER_PATHS = NO; 228 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 229 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 230 | CLANG_CXX_LIBRARY = "libc++"; 231 | CLANG_ENABLE_MODULES = YES; 232 | CLANG_ENABLE_OBJC_ARC = YES; 233 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 234 | CLANG_WARN_BOOL_CONVERSION = YES; 235 | CLANG_WARN_COMMA = YES; 236 | CLANG_WARN_CONSTANT_CONVERSION = YES; 237 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 238 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 239 | CLANG_WARN_EMPTY_BODY = YES; 240 | CLANG_WARN_ENUM_CONVERSION = YES; 241 | CLANG_WARN_INFINITE_RECURSION = YES; 242 | CLANG_WARN_INT_CONVERSION = YES; 243 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 244 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 245 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 246 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 247 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 248 | CLANG_WARN_STRICT_PROTOTYPES = YES; 249 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 250 | CLANG_WARN_UNREACHABLE_CODE = YES; 251 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 252 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 253 | COPY_PHASE_STRIP = NO; 254 | CURRENT_PROJECT_VERSION = 1; 255 | DEBUG_INFORMATION_FORMAT = dwarf; 256 | ENABLE_STRICT_OBJC_MSGSEND = YES; 257 | ENABLE_TESTABILITY = YES; 258 | GCC_C_LANGUAGE_STANDARD = gnu99; 259 | GCC_DYNAMIC_NO_PIC = NO; 260 | GCC_NO_COMMON_BLOCKS = YES; 261 | GCC_OPTIMIZATION_LEVEL = 0; 262 | GCC_PREPROCESSOR_DEFINITIONS = ( 263 | "DEBUG=1", 264 | "$(inherited)", 265 | ); 266 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 267 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 268 | GCC_WARN_UNDECLARED_SELECTOR = YES; 269 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 270 | GCC_WARN_UNUSED_FUNCTION = YES; 271 | GCC_WARN_UNUSED_VARIABLE = YES; 272 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 273 | MTL_ENABLE_DEBUG_INFO = YES; 274 | ONLY_ACTIVE_ARCH = YES; 275 | SDKROOT = iphoneos; 276 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 277 | SWIFT_VERSION = 4.2; 278 | TARGETED_DEVICE_FAMILY = "1,2"; 279 | VERSIONING_SYSTEM = "apple-generic"; 280 | VERSION_INFO_PREFIX = ""; 281 | }; 282 | name = Debug; 283 | }; 284 | B60EF8BB1C671A3E00FC0BBC /* Release */ = { 285 | isa = XCBuildConfiguration; 286 | buildSettings = { 287 | ALWAYS_SEARCH_USER_PATHS = NO; 288 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 289 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 290 | CLANG_CXX_LIBRARY = "libc++"; 291 | CLANG_ENABLE_MODULES = YES; 292 | CLANG_ENABLE_OBJC_ARC = YES; 293 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 294 | CLANG_WARN_BOOL_CONVERSION = YES; 295 | CLANG_WARN_COMMA = YES; 296 | CLANG_WARN_CONSTANT_CONVERSION = YES; 297 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 298 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 299 | CLANG_WARN_EMPTY_BODY = YES; 300 | CLANG_WARN_ENUM_CONVERSION = YES; 301 | CLANG_WARN_INFINITE_RECURSION = YES; 302 | CLANG_WARN_INT_CONVERSION = YES; 303 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 304 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 305 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 306 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 307 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 308 | CLANG_WARN_STRICT_PROTOTYPES = YES; 309 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 310 | CLANG_WARN_UNREACHABLE_CODE = YES; 311 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 312 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 313 | COPY_PHASE_STRIP = NO; 314 | CURRENT_PROJECT_VERSION = 1; 315 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 316 | ENABLE_NS_ASSERTIONS = NO; 317 | ENABLE_STRICT_OBJC_MSGSEND = YES; 318 | GCC_C_LANGUAGE_STANDARD = gnu99; 319 | GCC_NO_COMMON_BLOCKS = YES; 320 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 321 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 322 | GCC_WARN_UNDECLARED_SELECTOR = YES; 323 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 324 | GCC_WARN_UNUSED_FUNCTION = YES; 325 | GCC_WARN_UNUSED_VARIABLE = YES; 326 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 327 | MTL_ENABLE_DEBUG_INFO = NO; 328 | SDKROOT = iphoneos; 329 | SWIFT_COMPILATION_MODE = wholemodule; 330 | SWIFT_VERSION = 4.2; 331 | TARGETED_DEVICE_FAMILY = "1,2"; 332 | VALIDATE_PRODUCT = YES; 333 | VERSIONING_SYSTEM = "apple-generic"; 334 | VERSION_INFO_PREFIX = ""; 335 | }; 336 | name = Release; 337 | }; 338 | B60EF8BD1C671A3E00FC0BBC /* Debug */ = { 339 | isa = XCBuildConfiguration; 340 | buildSettings = { 341 | CLANG_ENABLE_MODULES = YES; 342 | CODE_SIGN_IDENTITY = ""; 343 | DEFINES_MODULE = YES; 344 | DYLIB_COMPATIBILITY_VERSION = 1; 345 | DYLIB_CURRENT_VERSION = 1; 346 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 347 | INFOPLIST_FILE = Notifwift/Info.plist; 348 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 349 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 350 | PRODUCT_BUNDLE_IDENTIFIER = takasek.Notifwift; 351 | PRODUCT_NAME = "$(TARGET_NAME)"; 352 | SKIP_INSTALL = YES; 353 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 354 | }; 355 | name = Debug; 356 | }; 357 | B60EF8BE1C671A3E00FC0BBC /* Release */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | CLANG_ENABLE_MODULES = YES; 361 | CODE_SIGN_IDENTITY = ""; 362 | DEFINES_MODULE = YES; 363 | DYLIB_COMPATIBILITY_VERSION = 1; 364 | DYLIB_CURRENT_VERSION = 1; 365 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 366 | INFOPLIST_FILE = Notifwift/Info.plist; 367 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 368 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 369 | PRODUCT_BUNDLE_IDENTIFIER = takasek.Notifwift; 370 | PRODUCT_NAME = "$(TARGET_NAME)"; 371 | SKIP_INSTALL = YES; 372 | }; 373 | name = Release; 374 | }; 375 | B60EF8C01C671A3E00FC0BBC /* Debug */ = { 376 | isa = XCBuildConfiguration; 377 | buildSettings = { 378 | INFOPLIST_FILE = NotifwiftTests/Info.plist; 379 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 380 | PRODUCT_BUNDLE_IDENTIFIER = takasek.NotifwiftTests; 381 | PRODUCT_NAME = "$(TARGET_NAME)"; 382 | }; 383 | name = Debug; 384 | }; 385 | B60EF8C11C671A3E00FC0BBC /* Release */ = { 386 | isa = XCBuildConfiguration; 387 | buildSettings = { 388 | INFOPLIST_FILE = NotifwiftTests/Info.plist; 389 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 390 | PRODUCT_BUNDLE_IDENTIFIER = takasek.NotifwiftTests; 391 | PRODUCT_NAME = "$(TARGET_NAME)"; 392 | }; 393 | name = Release; 394 | }; 395 | /* End XCBuildConfiguration section */ 396 | 397 | /* Begin XCConfigurationList section */ 398 | B60EF8A21C671A3E00FC0BBC /* Build configuration list for PBXProject "Notifwift" */ = { 399 | isa = XCConfigurationList; 400 | buildConfigurations = ( 401 | B60EF8BA1C671A3E00FC0BBC /* Debug */, 402 | B60EF8BB1C671A3E00FC0BBC /* Release */, 403 | ); 404 | defaultConfigurationIsVisible = 0; 405 | defaultConfigurationName = Release; 406 | }; 407 | B60EF8BC1C671A3E00FC0BBC /* Build configuration list for PBXNativeTarget "Notifwift" */ = { 408 | isa = XCConfigurationList; 409 | buildConfigurations = ( 410 | B60EF8BD1C671A3E00FC0BBC /* Debug */, 411 | B60EF8BE1C671A3E00FC0BBC /* Release */, 412 | ); 413 | defaultConfigurationIsVisible = 0; 414 | defaultConfigurationName = Release; 415 | }; 416 | B60EF8BF1C671A3E00FC0BBC /* Build configuration list for PBXNativeTarget "NotifwiftTests" */ = { 417 | isa = XCConfigurationList; 418 | buildConfigurations = ( 419 | B60EF8C01C671A3E00FC0BBC /* Debug */, 420 | B60EF8C11C671A3E00FC0BBC /* Release */, 421 | ); 422 | defaultConfigurationIsVisible = 0; 423 | defaultConfigurationName = Release; 424 | }; 425 | /* End XCConfigurationList section */ 426 | }; 427 | rootObject = B60EF89F1C671A3E00FC0BBC /* Project object */; 428 | } 429 | -------------------------------------------------------------------------------- /Notifwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Notifwift.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Notifwift.xcodeproj/xcshareddata/xcschemes/Notifwift.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 34 | 40 | 41 | 42 | 43 | 44 | 50 | 51 | 52 | 53 | 54 | 55 | 65 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | 83 | 84 | 90 | 91 | 92 | 93 | 95 | 96 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /Notifwift/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Notifwift/Notifwift.swift: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright © 2016年 Yoshitaka Seki (takasek). All rights reserved. 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | import Foundation 24 | 25 | public final class Notifwift { 26 | private static let payloadKey = "NotifwiftPayloadKey" 27 | 28 | private final class ObserverContainer { 29 | let name: Notification.Name 30 | let observer: NSObjectProtocol 31 | 32 | init(name: Notification.Name, object: Any?, queue: OperationQueue?, block: @escaping (_ notification: Notification) -> Void) { 33 | self.name = name 34 | self.observer = NotificationCenter.default.addObserver( 35 | forName: name, 36 | object: object, 37 | queue: queue, 38 | using: block 39 | ) 40 | } 41 | 42 | deinit { 43 | NotificationCenter.default.removeObserver(observer) 44 | } 45 | } 46 | 47 | private var pool = [ObserverContainer]() 48 | 49 | public init() {} 50 | 51 | public static func post(_ name: Notification.Name, from object: Any? = nil, payload: Any? = nil) { 52 | NotificationCenter.default.post( 53 | name: name, 54 | object: object, 55 | userInfo: payload.map { [Notifwift.payloadKey: $0] } 56 | ) 57 | } 58 | 59 | public func observe(_ name: Notification.Name, from object: Any? = nil, queue: OperationQueue? = nil, block: @escaping (_ notification: Notification) -> Void) { 60 | addToPool(name, object: object, queue: queue, block: block) 61 | } 62 | 63 | public func observe(_ name: Notification.Name, from object: Any? = nil, queue: OperationQueue? = nil, block: @escaping (_ notification: Notification, _ payload: T) -> Void) { 64 | addToPool(name, object: object, queue: queue) { [weak self] in 65 | guard let payload: T = self?.payload(from: $0) else { return } 66 | block($0, payload) 67 | } 68 | } 69 | 70 | public func observe(_ name: Notification.Name, from object: Any? = nil, queue: OperationQueue? = nil, block: @escaping (_ payload: T) -> Void) { 71 | addToPool(name, object: object, queue: queue) { [weak self] in 72 | guard let payload: T = self?.payload(from: $0) else { return } 73 | block(payload) 74 | } 75 | } 76 | 77 | public func dispose(_ name: Notification.Name) { 78 | removeFromPool(name) 79 | } 80 | 81 | // MARK: private methods 82 | private func addToPool(_ name: Notification.Name, object: Any?, queue: OperationQueue?, block: @escaping (Notification) -> Void) { 83 | pool.append(ObserverContainer(name: name, object: object, queue: queue, block: block)) 84 | } 85 | 86 | private func removeFromPool(_ name: Notification.Name) { 87 | pool = pool.filter { $0.name != name } 88 | } 89 | 90 | private func payload(from notification: Notification) -> T? { 91 | return notification.userInfo?[Notifwift.payloadKey] as? T 92 | } 93 | 94 | deinit { 95 | pool.removeAll() 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /NotifwiftTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /NotifwiftTests/NotifwiftTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NotifwiftTests.swift 3 | // NotifwiftTests 4 | // 5 | // Created by Yoshitaka Seki on 2016/02/07. 6 | // Copyright © 2016年 Yoshitaka Seki. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import Notifwift 11 | 12 | let notificationName = NSNotification.Name("Hoge") 13 | 14 | class NotifwiftTests: XCTestCase { 15 | 16 | func testLifecycle() { 17 | var received: Bool? 18 | 19 | do { 20 | let nt = Notifwift() 21 | nt.observe(notificationName) { notification in 22 | received = true 23 | } 24 | received = false 25 | Notifwift.post(notificationName) 26 | XCTAssertTrue(received!) 27 | } 28 | 29 | received = false 30 | Notifwift.post(notificationName) 31 | XCTAssertFalse(received!) 32 | } 33 | 34 | func testPayloads() { 35 | var payloadStr: Any? 36 | var payloadInt: Any? 37 | 38 | let nt = Notifwift() 39 | nt.observe(notificationName) { (p:String) in 40 | payloadStr = p 41 | } 42 | nt.observe(notificationName) { (p:Int) in 43 | payloadInt = p 44 | } 45 | 46 | payloadStr = nil 47 | payloadInt = nil 48 | Notifwift.post(notificationName, payload:"aaaa") 49 | XCTAssertEqual(payloadStr as? String, "aaaa") 50 | XCTAssertNil(payloadInt) 51 | 52 | payloadStr = nil 53 | payloadInt = nil 54 | Notifwift.post(notificationName, payload:1111) 55 | XCTAssertNil(payloadStr) 56 | XCTAssertEqual(payloadInt as? Int, 1111) 57 | } 58 | func testNotificationAndPayloads() { 59 | var payloadStr: Any? 60 | var payloadInt: Any? 61 | 62 | let nt = Notifwift() 63 | nt.observe(notificationName) { (_, p:String) in 64 | payloadStr = p 65 | } 66 | nt.observe(notificationName) { (_, p:Int) in 67 | payloadInt = p 68 | } 69 | 70 | payloadStr = nil 71 | payloadInt = nil 72 | Notifwift.post(notificationName, payload:"aaaa") 73 | XCTAssertEqual(payloadStr as? String, "aaaa") 74 | XCTAssertNil(payloadInt) 75 | 76 | payloadStr = nil 77 | payloadInt = nil 78 | Notifwift.post(notificationName, payload:1111) 79 | XCTAssertNil(payloadStr) 80 | XCTAssertEqual(payloadInt as? Int, 1111) 81 | } 82 | 83 | func testSubtype() { 84 | var received: Bool? 85 | var receivedSub: Bool? 86 | 87 | class Animal {} 88 | class Cat: Animal {} 89 | 90 | let nt = Notifwift() 91 | nt.observe(notificationName) { (_, p:Animal) in 92 | received = true 93 | } 94 | nt.observe(notificationName) { (_, p:Cat) in 95 | receivedSub = true 96 | } 97 | 98 | received = false 99 | receivedSub = false 100 | Notifwift.post(notificationName, payload:Animal()) 101 | XCTAssertTrue(received!) 102 | XCTAssertFalse(receivedSub!) 103 | 104 | received = false 105 | receivedSub = false 106 | Notifwift.post(notificationName, payload:Cat()) 107 | XCTAssertTrue(received!) 108 | XCTAssertTrue(receivedSub!) 109 | } 110 | 111 | func testObjects() { 112 | var received: Bool? 113 | var receivedFromObj1: Bool? 114 | var receivedFromObj2: Bool? 115 | 116 | let obj1 = NSObject() 117 | let obj2 = NSObject() 118 | let nt = Notifwift() 119 | nt.observe(notificationName) { _ in 120 | received = true 121 | } 122 | nt.observe(notificationName, from: obj1) { _ in 123 | receivedFromObj1 = true 124 | } 125 | nt.observe(notificationName, from: obj2) { _ in 126 | receivedFromObj2 = true 127 | } 128 | 129 | received = false 130 | receivedFromObj1 = false 131 | receivedFromObj2 = false 132 | Notifwift.post(notificationName, from: obj1) 133 | XCTAssertTrue(received!) 134 | XCTAssertTrue(receivedFromObj1!) 135 | XCTAssertFalse(receivedFromObj2!) 136 | 137 | received = false 138 | receivedFromObj1 = false 139 | receivedFromObj2 = false 140 | Notifwift.post(notificationName, from: obj2) 141 | XCTAssertTrue(received!) 142 | XCTAssertFalse(receivedFromObj1!) 143 | XCTAssertTrue(receivedFromObj2!) 144 | } 145 | 146 | func testDispose() { 147 | var payloadStr: Any? 148 | var payloadInt: Any? 149 | 150 | let nt = Notifwift() 151 | nt.observe(notificationName) { (p:String) in 152 | payloadStr = p 153 | } 154 | nt.observe(notificationName) { (p:Int) in 155 | payloadInt = p 156 | } 157 | 158 | payloadStr = nil 159 | payloadInt = nil 160 | Notifwift.post(notificationName, payload:"aaaa") 161 | Notifwift.post(notificationName, payload:1111) 162 | XCTAssertEqual(payloadStr as? String, "aaaa") 163 | XCTAssertEqual(payloadInt as? Int, 1111) 164 | 165 | payloadStr = nil 166 | payloadInt = nil 167 | nt.dispose(notificationName) 168 | Notifwift.post(notificationName, payload:"aaaa") 169 | Notifwift.post(notificationName, payload:1111) 170 | XCTAssertNil(payloadStr) 171 | XCTAssertNil(payloadInt) 172 | 173 | var received: Bool? 174 | var receivedFromObj1: Bool? 175 | var receivedFromObj2: Bool? 176 | 177 | // MARK: with `from` object. 178 | let obj1 = NSObject() 179 | let obj2 = NSObject() 180 | nt.observe(notificationName) { _ in 181 | received = true 182 | } 183 | nt.observe(notificationName, from: obj1) { _ in 184 | receivedFromObj1 = true 185 | } 186 | nt.observe(notificationName, from: obj2) { _ in 187 | receivedFromObj2 = true 188 | } 189 | 190 | received = false 191 | receivedFromObj1 = false 192 | receivedFromObj2 = false 193 | Notifwift.post(notificationName, from: obj1) 194 | XCTAssertTrue(received!) 195 | XCTAssertTrue(receivedFromObj1!) 196 | XCTAssertFalse(receivedFromObj2!) 197 | 198 | received = false 199 | receivedFromObj1 = false 200 | receivedFromObj2 = false 201 | nt.dispose(notificationName) 202 | Notifwift.post(notificationName, from: obj2) 203 | XCTAssertFalse(received!) 204 | XCTAssertFalse(receivedFromObj1!) 205 | XCTAssertFalse(receivedFromObj2!) 206 | 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:4.2 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "Notifwift", 7 | products: [ 8 | .library(name: "Notifwift", targets: ["Notifwift"]), 9 | ], 10 | targets: [ 11 | .target(name: "Notifwift", path: "Notifwift"), 12 | ] 13 | ) 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Notifwift 2 | 3 | [![Version](https://img.shields.io/cocoapods/v/Notifwift.svg?style=flat)](http://cocoapods.org/pods/Notifwift) 4 | [![License](https://img.shields.io/cocoapods/l/Notifwift.svg?style=flat)](http://cocoapods.org/pods/Notifwift) 5 | [![Platform](https://img.shields.io/cocoapods/p/Notifwift.svg?style=flat)](http://cocoapods.org/pods/Notifwift) 6 | [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 7 | 8 | Notifwift is the NS**Notif**icationCenter wrapper for S**wift**. 9 | 10 | Notifwift resolves; 11 | 12 | - cumbersome management of Notification observers 13 | - meaningless dictionary key required for Notification.userInfo 14 | - long syntax to post/observe notifications 15 | 16 | 17 | ## Usage 18 | 19 | ```swift 20 | let notificationName = Notification.Name(rawValue: "YourNotificationName") 21 | do { 22 | let notifwift = Notifwift() 23 | notifwift.observe(notificationName) {(notification) in 24 | print("Notifwift can observe Notification in simple way.", notification) 25 | } 26 | Notifwift.post(notificationName) 27 | //printed: 28 | // Notifwift can observe Notification in simple way. name = YourNotificationName, object = nil, userInfo = nil 29 | } 30 | 31 | Notifwift.post(notificationName) 32 | //printed nothing. Observers expire when the Notifwift instance(in this case) is destructed. 33 | ``` 34 | 35 | ```swift 36 | let notifwift = Notifwift() 37 | notifwift.observe(notificationName) { (payload: String) in 38 | print("This closure observes nothing but Notification with String payload.", payload) 39 | } 40 | notifwift.observe(notificationName) { (payload: Int) in 41 | print("This closure observes nothing but Notification with Int payload.", payload) 42 | } 43 | 44 | Notifwift.post(notificationName, payload:"aaaa") 45 | //printed: 46 | // This closure observes nothing but Notification with String payload. aaaa 47 | 48 | Notifwift.post(notificationName, payload:1) 49 | //printed: 50 | // This closure observes nothing but Notification with Int payload. 1 51 | ``` 52 | 53 | The receiver block accepts: 54 | 55 | - `(Notification) -> Void` 56 | - `(Notification, T) -> Void` 57 | - `(T) -> Void` 58 | 59 | ```swift 60 | class Animal {} 61 | class Cat: Animal {} 62 | 63 | let notifwift = Notifwift() 64 | notifwift.observe(notificationName) { (_, p:Animal) in 65 | print("Received Animal.", p) 66 | } 67 | notifwift.observe(notificationName) { (_, p:Cat) in 68 | print("Received Cat. Yes, of course, Notifwift recognizes subtypes.", p) 69 | } 70 | 71 | Notifwift.post(notificationName, payload:Animal()) 72 | //printed: 73 | // Received Animal. (Animal #1) 74 | 75 | Notifwift.post(notificationName, payload:Cat()) 76 | //printed: 77 | // Received Animal. (Cat #1) 78 | // Received Cat. Yes, of course, Notifwift recognizes subtypes. (Cat #1) 79 | ``` 80 | 81 | ```swift 82 | enum SomeResult { 83 | case Success(String) 84 | case Fail(NSError) 85 | } 86 | let notifwift = Notifwift() 87 | notifwift.observe(notificationName) { (_, p:SomeResult) in 88 | switch p { 89 | case .Success(let str): 90 | print("Any Type can be used as a payload", str) 91 | case .Fail(let err) where err.code == 403: 92 | print("not authorized") 93 | case .Fail(let err) where err.code == 404: 94 | print("not found") 95 | case .Fail(let err): 96 | print("Notifwift has a chemistry with Enum Associated Values.", err) 97 | } 98 | } 99 | 100 | Notifwift.post(notificationName, payload:SomeResult.Success("like this.")) 101 | //printed: 102 | // Any Type can be used as a payload like this. 103 | 104 | Notifwift.post(notificationName, payload:SomeResult.Fail(NSError(domain: "", code: 0, userInfo: nil))) 105 | //printed: 106 | // Notifwift has a chemistry with Enum Associated Values. Error Domain= Code=0 "(null)" 107 | ``` 108 | 109 | ```swift 110 | let obj1 = NSObject() 111 | let obj2 = NSObject() 112 | let notifwift = Notifwift() 113 | notifwift.observe(notificationName) { _ in 114 | print("Received from all objects") 115 | } 116 | notifwift.observe(notificationName, from: obj1) { _ in 117 | print("Received from obj1 only") 118 | } 119 | notifwift.observe(notificationName, from: obj2) { _ in 120 | print("Received from obj2 only") 121 | } 122 | 123 | Notifwift.post(notificationName, from: obj1) 124 | //printed: 125 | // Received from all objects 126 | // Received from obj1 only 127 | 128 | Notifwift.post(notificationName, from: obj2) 129 | //printed: 130 | // Received from all objects 131 | // Received from obj2 only 132 | ``` 133 | 134 | Since the registered observers for notifications are to disposed automatically when the Notifwift instance is dead, you can dispose them by your self. 135 | 136 | ``` 137 | notifwift.dispose(dispose) 138 | ``` 139 | 140 | 141 | ## Real World Example 142 | 143 | Here's an example usage. 144 | 145 | ```swift 146 | let didReceiveUserNotification = Notification.Name(rawValue: "didReceiveUserNotification") 147 | 148 | final class MyViewController: UIViewController { 149 | @IBOutlet var userInfoView: MyUserInfoView! 150 | let notifwift = Notifwift() 151 | 152 | override func viewDidLoad() { 153 | super.viewDidLoad() 154 | notifwift.observe(didReceiveUserNotification) { [unowned self] in self.reload($0) } //Use `weak` or `unowned` on calling the self methods to avoid retain cycles. 155 | } 156 | 157 | private func reload(user: User) { 158 | userInfoView.reload(user) 159 | } 160 | } 161 | 162 | final class MyUserRepository { 163 | func fetchUser(id: Int) { 164 | MyAPIManager.fetchUser(id) { (user: User) in 165 | Notifwift.post(didReceiveUserNotification, payload: user) 166 | } 167 | } 168 | } 169 | 170 | ``` 171 | 172 | The Notifwift instance is alive during MyViewController instance. 173 | It dies when MyViewController instance dies, so observers registered in the Notifwift instance are to be removed automatically. Never mind if you have to manage observer! 174 | 175 | ## Installation 176 | 177 | Notifwift is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile: 178 | 179 | ```ruby 180 | pod "Notifwift" 181 | ``` 182 | 183 | Notifwift is available through [Carthage](https://github.com/Carthage/Carthage). To install it, simply add the following line to your Cartfile: 184 | 185 | ```ruby 186 | github "takasek/Notifwift" 187 | ``` 188 | 189 | ## Author 190 | 191 | [takasek](https://twitter.com/takasek) 192 | 193 | ## License 194 | 195 | Notifwift is available under the MIT license. See the LICENSE file for more info. 196 | --------------------------------------------------------------------------------