├── .gitignore ├── Common └── MagicServiceProtocol.swift ├── Magic 8 Ball.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── Magic 8 Ball ├── AppController.swift ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ └── MainMenu.xib ├── Info.plist ├── Magic 8 Ball.entitlements └── NSWindow+Shaking.swift ├── MagicXPCService ├── Info.plist ├── ListenerDelegate.swift ├── MagicXPCService.entitlements ├── MagicXPCService.swift └── main.swift └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .AppleDouble 3 | .LSOverride 4 | 5 | # Icon 6 | Icon 7 | 8 | 9 | # Thumbnails 10 | ._* 11 | 12 | # Files that might appear in the root of a volume 13 | .DocumentRevisions-V100 14 | .fseventsd 15 | .Spotlight-V100 16 | .TemporaryItems 17 | .Trashes 18 | .VolumeIcon.icns 19 | 20 | # Directories potentially created on remote AFP share 21 | .AppleDB 22 | .AppleDesktop 23 | 24 | .apdisk 25 | 26 | #Xcode-specific 27 | *.xcodeproj/project.xcworkspace/xcuserdata/ 28 | *.xcodeproj/xcuserdata/ 29 | */*.xcodeproj/xcuserdata/ 30 | *.xcworkspace/xcuserdata/ 31 | -------------------------------------------------------------------------------- /Common/MagicServiceProtocol.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 aronskaya (Julia Vashchenko) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import Foundation 26 | 27 | //This file is included in both UI and XPC Service targets for the sake of simplicity. 28 | 29 | let kServiceName = "com.vashchenko.MagicXPCService" 30 | 31 | typealias DecisionReplyBlock = (String) -> () 32 | 33 | @objc protocol MagicServiceProtocol { 34 | func getDecision(replyBlock: @escaping DecisionReplyBlock) 35 | } 36 | -------------------------------------------------------------------------------- /Magic 8 Ball.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6929560521F701100002F972 /* MagicXPCService.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 692955FA21F701100002F972 /* MagicXPCService.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 11 | 6929560B21F701330002F972 /* MagicServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6929560A21F701330002F972 /* MagicServiceProtocol.swift */; }; 12 | 6929560D21F701E90002F972 /* MagicXPCService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6929560C21F701E90002F972 /* MagicXPCService.swift */; }; 13 | 6929560E21F702060002F972 /* MagicServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6929560A21F701330002F972 /* MagicServiceProtocol.swift */; }; 14 | 6929561021F702260002F972 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6929560F21F702260002F972 /* main.swift */; }; 15 | 6929561221F7024B0002F972 /* ListenerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6929561121F7024B0002F972 /* ListenerDelegate.swift */; }; 16 | 693F55DC21F9FF3D00778251 /* NSWindow+Shaking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 693F55DB21F9FF3D00778251 /* NSWindow+Shaking.swift */; }; 17 | 697DEE0B21F50E0600A4D6DC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 697DEE0A21F50E0600A4D6DC /* AppDelegate.swift */; }; 18 | 697DEE0D21F50E0700A4D6DC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 697DEE0C21F50E0700A4D6DC /* Assets.xcassets */; }; 19 | 697DEE1021F50E0700A4D6DC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 697DEE0E21F50E0700A4D6DC /* MainMenu.xib */; }; 20 | 697DEE2D21F5134700A4D6DC /* AppController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 697DEE2C21F5134700A4D6DC /* AppController.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 6929560321F701100002F972 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 697DEDFF21F50E0600A4D6DC /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 692955F921F701100002F972; 29 | remoteInfo = MagicXPCService; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXCopyFilesBuildPhase section */ 34 | 697DEE2B21F50E6C00A4D6DC /* Embed XPC Services */ = { 35 | isa = PBXCopyFilesBuildPhase; 36 | buildActionMask = 2147483647; 37 | dstPath = "$(CONTENTS_FOLDER_PATH)/XPCServices"; 38 | dstSubfolderSpec = 16; 39 | files = ( 40 | 6929560521F701100002F972 /* MagicXPCService.xpc in Embed XPC Services */, 41 | ); 42 | name = "Embed XPC Services"; 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXCopyFilesBuildPhase section */ 46 | 47 | /* Begin PBXFileReference section */ 48 | 692955F321F644070002F972 /* Magic 8 Ball.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Magic 8 Ball.entitlements"; sourceTree = ""; }; 49 | 692955FA21F701100002F972 /* MagicXPCService.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = MagicXPCService.xpc; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 6929560221F701100002F972 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | 6929560A21F701330002F972 /* MagicServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MagicServiceProtocol.swift; sourceTree = ""; }; 52 | 6929560C21F701E90002F972 /* MagicXPCService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MagicXPCService.swift; sourceTree = ""; }; 53 | 6929560F21F702260002F972 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 54 | 6929561121F7024B0002F972 /* ListenerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListenerDelegate.swift; sourceTree = ""; }; 55 | 6929561321F7050B0002F972 /* MagicXPCService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MagicXPCService.entitlements; sourceTree = ""; }; 56 | 693F55DB21F9FF3D00778251 /* NSWindow+Shaking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSWindow+Shaking.swift"; sourceTree = ""; }; 57 | 697DEE0721F50E0600A4D6DC /* Magic 8 Ball.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Magic 8 Ball.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 58 | 697DEE0A21F50E0600A4D6DC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 59 | 697DEE0C21F50E0700A4D6DC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 60 | 697DEE0F21F50E0700A4D6DC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 61 | 697DEE1121F50E0700A4D6DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 62 | 697DEE2C21F5134700A4D6DC /* AppController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppController.swift; sourceTree = ""; }; 63 | 697DEE3121F5180B00A4D6DC /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 64 | /* End PBXFileReference section */ 65 | 66 | /* Begin PBXFrameworksBuildPhase section */ 67 | 692955F721F701100002F972 /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | 697DEE0421F50E0600A4D6DC /* Frameworks */ = { 75 | isa = PBXFrameworksBuildPhase; 76 | buildActionMask = 2147483647; 77 | files = ( 78 | ); 79 | runOnlyForDeploymentPostprocessing = 0; 80 | }; 81 | /* End PBXFrameworksBuildPhase section */ 82 | 83 | /* Begin PBXGroup section */ 84 | 692955F521F700D20002F972 /* Common */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 6929560A21F701330002F972 /* MagicServiceProtocol.swift */, 88 | ); 89 | path = Common; 90 | sourceTree = ""; 91 | }; 92 | 692955FB21F701100002F972 /* MagicXPCService */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 6929560F21F702260002F972 /* main.swift */, 96 | 6929561121F7024B0002F972 /* ListenerDelegate.swift */, 97 | 6929560C21F701E90002F972 /* MagicXPCService.swift */, 98 | 6929560221F701100002F972 /* Info.plist */, 99 | 6929561321F7050B0002F972 /* MagicXPCService.entitlements */, 100 | ); 101 | path = MagicXPCService; 102 | sourceTree = ""; 103 | }; 104 | 697DEDFE21F50E0600A4D6DC = { 105 | isa = PBXGroup; 106 | children = ( 107 | 697DEE3121F5180B00A4D6DC /* README.md */, 108 | 697DEE0921F50E0600A4D6DC /* Magic 8 Ball */, 109 | 692955FB21F701100002F972 /* MagicXPCService */, 110 | 692955F521F700D20002F972 /* Common */, 111 | 697DEE0821F50E0600A4D6DC /* Products */, 112 | ); 113 | sourceTree = ""; 114 | }; 115 | 697DEE0821F50E0600A4D6DC /* Products */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 697DEE0721F50E0600A4D6DC /* Magic 8 Ball.app */, 119 | 692955FA21F701100002F972 /* MagicXPCService.xpc */, 120 | ); 121 | name = Products; 122 | sourceTree = ""; 123 | }; 124 | 697DEE0921F50E0600A4D6DC /* Magic 8 Ball */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 697DEE0A21F50E0600A4D6DC /* AppDelegate.swift */, 128 | 697DEE2C21F5134700A4D6DC /* AppController.swift */, 129 | 697DEE0E21F50E0700A4D6DC /* MainMenu.xib */, 130 | 693F55DB21F9FF3D00778251 /* NSWindow+Shaking.swift */, 131 | 697DEE1121F50E0700A4D6DC /* Info.plist */, 132 | 697DEE0C21F50E0700A4D6DC /* Assets.xcassets */, 133 | 692955F321F644070002F972 /* Magic 8 Ball.entitlements */, 134 | ); 135 | path = "Magic 8 Ball"; 136 | sourceTree = ""; 137 | }; 138 | /* End PBXGroup section */ 139 | 140 | /* Begin PBXNativeTarget section */ 141 | 692955F921F701100002F972 /* MagicXPCService */ = { 142 | isa = PBXNativeTarget; 143 | buildConfigurationList = 6929560621F701100002F972 /* Build configuration list for PBXNativeTarget "MagicXPCService" */; 144 | buildPhases = ( 145 | 692955F621F701100002F972 /* Sources */, 146 | 692955F721F701100002F972 /* Frameworks */, 147 | 692955F821F701100002F972 /* Resources */, 148 | ); 149 | buildRules = ( 150 | ); 151 | dependencies = ( 152 | ); 153 | name = MagicXPCService; 154 | productName = MagicXPCService; 155 | productReference = 692955FA21F701100002F972 /* MagicXPCService.xpc */; 156 | productType = "com.apple.product-type.xpc-service"; 157 | }; 158 | 697DEE0621F50E0600A4D6DC /* Magic 8 Ball */ = { 159 | isa = PBXNativeTarget; 160 | buildConfigurationList = 697DEE1521F50E0700A4D6DC /* Build configuration list for PBXNativeTarget "Magic 8 Ball" */; 161 | buildPhases = ( 162 | 697DEE0321F50E0600A4D6DC /* Sources */, 163 | 697DEE0421F50E0600A4D6DC /* Frameworks */, 164 | 697DEE0521F50E0600A4D6DC /* Resources */, 165 | 697DEE2B21F50E6C00A4D6DC /* Embed XPC Services */, 166 | ); 167 | buildRules = ( 168 | ); 169 | dependencies = ( 170 | 6929560421F701100002F972 /* PBXTargetDependency */, 171 | ); 172 | name = "Magic 8 Ball"; 173 | productName = "Magic 8 Ball"; 174 | productReference = 697DEE0721F50E0600A4D6DC /* Magic 8 Ball.app */; 175 | productType = "com.apple.product-type.application"; 176 | }; 177 | /* End PBXNativeTarget section */ 178 | 179 | /* Begin PBXProject section */ 180 | 697DEDFF21F50E0600A4D6DC /* Project object */ = { 181 | isa = PBXProject; 182 | attributes = { 183 | LastSwiftUpdateCheck = 1000; 184 | LastUpgradeCheck = 1000; 185 | ORGANIZATIONNAME = "Julia Vashchenko"; 186 | TargetAttributes = { 187 | 692955F921F701100002F972 = { 188 | CreatedOnToolsVersion = 10.0; 189 | LastSwiftMigration = 1000; 190 | SystemCapabilities = { 191 | com.apple.Sandbox = { 192 | enabled = 1; 193 | }; 194 | }; 195 | }; 196 | 697DEE0621F50E0600A4D6DC = { 197 | CreatedOnToolsVersion = 10.0; 198 | SystemCapabilities = { 199 | com.apple.Sandbox = { 200 | enabled = 1; 201 | }; 202 | }; 203 | }; 204 | }; 205 | }; 206 | buildConfigurationList = 697DEE0221F50E0600A4D6DC /* Build configuration list for PBXProject "Magic 8 Ball" */; 207 | compatibilityVersion = "Xcode 9.3"; 208 | developmentRegion = en; 209 | hasScannedForEncodings = 0; 210 | knownRegions = ( 211 | en, 212 | Base, 213 | ); 214 | mainGroup = 697DEDFE21F50E0600A4D6DC; 215 | productRefGroup = 697DEE0821F50E0600A4D6DC /* Products */; 216 | projectDirPath = ""; 217 | projectRoot = ""; 218 | targets = ( 219 | 697DEE0621F50E0600A4D6DC /* Magic 8 Ball */, 220 | 692955F921F701100002F972 /* MagicXPCService */, 221 | ); 222 | }; 223 | /* End PBXProject section */ 224 | 225 | /* Begin PBXResourcesBuildPhase section */ 226 | 692955F821F701100002F972 /* Resources */ = { 227 | isa = PBXResourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | 697DEE0521F50E0600A4D6DC /* Resources */ = { 234 | isa = PBXResourcesBuildPhase; 235 | buildActionMask = 2147483647; 236 | files = ( 237 | 697DEE0D21F50E0700A4D6DC /* Assets.xcassets in Resources */, 238 | 697DEE1021F50E0700A4D6DC /* MainMenu.xib in Resources */, 239 | ); 240 | runOnlyForDeploymentPostprocessing = 0; 241 | }; 242 | /* End PBXResourcesBuildPhase section */ 243 | 244 | /* Begin PBXSourcesBuildPhase section */ 245 | 692955F621F701100002F972 /* Sources */ = { 246 | isa = PBXSourcesBuildPhase; 247 | buildActionMask = 2147483647; 248 | files = ( 249 | 6929560D21F701E90002F972 /* MagicXPCService.swift in Sources */, 250 | 6929560B21F701330002F972 /* MagicServiceProtocol.swift in Sources */, 251 | 6929561221F7024B0002F972 /* ListenerDelegate.swift in Sources */, 252 | 6929561021F702260002F972 /* main.swift in Sources */, 253 | ); 254 | runOnlyForDeploymentPostprocessing = 0; 255 | }; 256 | 697DEE0321F50E0600A4D6DC /* Sources */ = { 257 | isa = PBXSourcesBuildPhase; 258 | buildActionMask = 2147483647; 259 | files = ( 260 | 697DEE0B21F50E0600A4D6DC /* AppDelegate.swift in Sources */, 261 | 697DEE2D21F5134700A4D6DC /* AppController.swift in Sources */, 262 | 693F55DC21F9FF3D00778251 /* NSWindow+Shaking.swift in Sources */, 263 | 6929560E21F702060002F972 /* MagicServiceProtocol.swift in Sources */, 264 | ); 265 | runOnlyForDeploymentPostprocessing = 0; 266 | }; 267 | /* End PBXSourcesBuildPhase section */ 268 | 269 | /* Begin PBXTargetDependency section */ 270 | 6929560421F701100002F972 /* PBXTargetDependency */ = { 271 | isa = PBXTargetDependency; 272 | target = 692955F921F701100002F972 /* MagicXPCService */; 273 | targetProxy = 6929560321F701100002F972 /* PBXContainerItemProxy */; 274 | }; 275 | /* End PBXTargetDependency section */ 276 | 277 | /* Begin PBXVariantGroup section */ 278 | 697DEE0E21F50E0700A4D6DC /* MainMenu.xib */ = { 279 | isa = PBXVariantGroup; 280 | children = ( 281 | 697DEE0F21F50E0700A4D6DC /* Base */, 282 | ); 283 | name = MainMenu.xib; 284 | sourceTree = ""; 285 | }; 286 | /* End PBXVariantGroup section */ 287 | 288 | /* Begin XCBuildConfiguration section */ 289 | 6929560721F701100002F972 /* Debug */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 293 | CLANG_ENABLE_MODULES = YES; 294 | CODE_SIGN_ENTITLEMENTS = MagicXPCService/MagicXPCService.entitlements; 295 | CODE_SIGN_STYLE = Automatic; 296 | COMBINE_HIDPI_IMAGES = YES; 297 | DEVELOPMENT_TEAM = CZPU3C72KU; 298 | INFOPLIST_FILE = MagicXPCService/Info.plist; 299 | LD_RUNPATH_SEARCH_PATHS = ( 300 | "$(inherited)", 301 | "@executable_path/../Frameworks", 302 | "@loader_path/../Frameworks", 303 | ); 304 | PRODUCT_BUNDLE_IDENTIFIER = com.vashchenko.MagicXPCService; 305 | PRODUCT_NAME = "$(TARGET_NAME)"; 306 | SKIP_INSTALL = YES; 307 | SWIFT_OBJC_BRIDGING_HEADER = ""; 308 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 309 | SWIFT_VERSION = 4.2; 310 | }; 311 | name = Debug; 312 | }; 313 | 6929560821F701100002F972 /* Release */ = { 314 | isa = XCBuildConfiguration; 315 | buildSettings = { 316 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 317 | CLANG_ENABLE_MODULES = YES; 318 | CODE_SIGN_ENTITLEMENTS = MagicXPCService/MagicXPCService.entitlements; 319 | CODE_SIGN_STYLE = Automatic; 320 | COMBINE_HIDPI_IMAGES = YES; 321 | DEVELOPMENT_TEAM = CZPU3C72KU; 322 | INFOPLIST_FILE = MagicXPCService/Info.plist; 323 | LD_RUNPATH_SEARCH_PATHS = ( 324 | "$(inherited)", 325 | "@executable_path/../Frameworks", 326 | "@loader_path/../Frameworks", 327 | ); 328 | PRODUCT_BUNDLE_IDENTIFIER = com.vashchenko.MagicXPCService; 329 | PRODUCT_NAME = "$(TARGET_NAME)"; 330 | SKIP_INSTALL = YES; 331 | SWIFT_OBJC_BRIDGING_HEADER = ""; 332 | SWIFT_VERSION = 4.2; 333 | }; 334 | name = Release; 335 | }; 336 | 697DEE1321F50E0700A4D6DC /* Debug */ = { 337 | isa = XCBuildConfiguration; 338 | buildSettings = { 339 | ALWAYS_SEARCH_USER_PATHS = NO; 340 | CLANG_ANALYZER_NONNULL = YES; 341 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 342 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 343 | CLANG_CXX_LIBRARY = "libc++"; 344 | CLANG_ENABLE_MODULES = YES; 345 | CLANG_ENABLE_OBJC_ARC = YES; 346 | CLANG_ENABLE_OBJC_WEAK = YES; 347 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 348 | CLANG_WARN_BOOL_CONVERSION = YES; 349 | CLANG_WARN_COMMA = YES; 350 | CLANG_WARN_CONSTANT_CONVERSION = YES; 351 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 352 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 353 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 354 | CLANG_WARN_EMPTY_BODY = YES; 355 | CLANG_WARN_ENUM_CONVERSION = YES; 356 | CLANG_WARN_INFINITE_RECURSION = YES; 357 | CLANG_WARN_INT_CONVERSION = YES; 358 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 359 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 360 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 361 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 362 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 363 | CLANG_WARN_STRICT_PROTOTYPES = YES; 364 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 365 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 366 | CLANG_WARN_UNREACHABLE_CODE = YES; 367 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 368 | CODE_SIGN_IDENTITY = "Mac Developer"; 369 | COPY_PHASE_STRIP = NO; 370 | DEBUG_INFORMATION_FORMAT = dwarf; 371 | ENABLE_STRICT_OBJC_MSGSEND = YES; 372 | ENABLE_TESTABILITY = YES; 373 | GCC_C_LANGUAGE_STANDARD = gnu11; 374 | GCC_DYNAMIC_NO_PIC = NO; 375 | GCC_NO_COMMON_BLOCKS = YES; 376 | GCC_OPTIMIZATION_LEVEL = 0; 377 | GCC_PREPROCESSOR_DEFINITIONS = ( 378 | "DEBUG=1", 379 | "$(inherited)", 380 | ); 381 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 382 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 383 | GCC_WARN_UNDECLARED_SELECTOR = YES; 384 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 385 | GCC_WARN_UNUSED_FUNCTION = YES; 386 | GCC_WARN_UNUSED_VARIABLE = YES; 387 | MACOSX_DEPLOYMENT_TARGET = 10.14; 388 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 389 | MTL_FAST_MATH = YES; 390 | ONLY_ACTIVE_ARCH = YES; 391 | SDKROOT = macosx; 392 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 393 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 394 | }; 395 | name = Debug; 396 | }; 397 | 697DEE1421F50E0700A4D6DC /* Release */ = { 398 | isa = XCBuildConfiguration; 399 | buildSettings = { 400 | ALWAYS_SEARCH_USER_PATHS = NO; 401 | CLANG_ANALYZER_NONNULL = YES; 402 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 403 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 404 | CLANG_CXX_LIBRARY = "libc++"; 405 | CLANG_ENABLE_MODULES = YES; 406 | CLANG_ENABLE_OBJC_ARC = YES; 407 | CLANG_ENABLE_OBJC_WEAK = YES; 408 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 409 | CLANG_WARN_BOOL_CONVERSION = YES; 410 | CLANG_WARN_COMMA = YES; 411 | CLANG_WARN_CONSTANT_CONVERSION = YES; 412 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 413 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 414 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 415 | CLANG_WARN_EMPTY_BODY = YES; 416 | CLANG_WARN_ENUM_CONVERSION = YES; 417 | CLANG_WARN_INFINITE_RECURSION = YES; 418 | CLANG_WARN_INT_CONVERSION = YES; 419 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 420 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 421 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 422 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 423 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 424 | CLANG_WARN_STRICT_PROTOTYPES = YES; 425 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 426 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 427 | CLANG_WARN_UNREACHABLE_CODE = YES; 428 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 429 | CODE_SIGN_IDENTITY = "Mac Developer"; 430 | COPY_PHASE_STRIP = NO; 431 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 432 | ENABLE_NS_ASSERTIONS = NO; 433 | ENABLE_STRICT_OBJC_MSGSEND = YES; 434 | GCC_C_LANGUAGE_STANDARD = gnu11; 435 | GCC_NO_COMMON_BLOCKS = YES; 436 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 437 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 438 | GCC_WARN_UNDECLARED_SELECTOR = YES; 439 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 440 | GCC_WARN_UNUSED_FUNCTION = YES; 441 | GCC_WARN_UNUSED_VARIABLE = YES; 442 | MACOSX_DEPLOYMENT_TARGET = 10.14; 443 | MTL_ENABLE_DEBUG_INFO = NO; 444 | MTL_FAST_MATH = YES; 445 | SDKROOT = macosx; 446 | SWIFT_COMPILATION_MODE = wholemodule; 447 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 448 | }; 449 | name = Release; 450 | }; 451 | 697DEE1621F50E0700A4D6DC /* Debug */ = { 452 | isa = XCBuildConfiguration; 453 | buildSettings = { 454 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 455 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 456 | CODE_SIGN_ENTITLEMENTS = "Magic 8 Ball/Magic 8 Ball.entitlements"; 457 | CODE_SIGN_STYLE = Automatic; 458 | COMBINE_HIDPI_IMAGES = YES; 459 | DEVELOPMENT_TEAM = CZPU3C72KU; 460 | INFOPLIST_FILE = "Magic 8 Ball/Info.plist"; 461 | LD_RUNPATH_SEARCH_PATHS = ( 462 | "$(inherited)", 463 | "@executable_path/../Frameworks", 464 | ); 465 | PRODUCT_BUNDLE_IDENTIFIER = "com.vashchenko.Magic-8-Ball"; 466 | PRODUCT_NAME = "$(TARGET_NAME)"; 467 | SWIFT_OBJC_BRIDGING_HEADER = ""; 468 | SWIFT_VERSION = 4.2; 469 | }; 470 | name = Debug; 471 | }; 472 | 697DEE1721F50E0700A4D6DC /* Release */ = { 473 | isa = XCBuildConfiguration; 474 | buildSettings = { 475 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 476 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 477 | CODE_SIGN_ENTITLEMENTS = "Magic 8 Ball/Magic 8 Ball.entitlements"; 478 | CODE_SIGN_STYLE = Automatic; 479 | COMBINE_HIDPI_IMAGES = YES; 480 | DEVELOPMENT_TEAM = CZPU3C72KU; 481 | INFOPLIST_FILE = "Magic 8 Ball/Info.plist"; 482 | LD_RUNPATH_SEARCH_PATHS = ( 483 | "$(inherited)", 484 | "@executable_path/../Frameworks", 485 | ); 486 | PRODUCT_BUNDLE_IDENTIFIER = "com.vashchenko.Magic-8-Ball"; 487 | PRODUCT_NAME = "$(TARGET_NAME)"; 488 | SWIFT_OBJC_BRIDGING_HEADER = ""; 489 | SWIFT_VERSION = 4.2; 490 | }; 491 | name = Release; 492 | }; 493 | /* End XCBuildConfiguration section */ 494 | 495 | /* Begin XCConfigurationList section */ 496 | 6929560621F701100002F972 /* Build configuration list for PBXNativeTarget "MagicXPCService" */ = { 497 | isa = XCConfigurationList; 498 | buildConfigurations = ( 499 | 6929560721F701100002F972 /* Debug */, 500 | 6929560821F701100002F972 /* Release */, 501 | ); 502 | defaultConfigurationIsVisible = 0; 503 | defaultConfigurationName = Release; 504 | }; 505 | 697DEE0221F50E0600A4D6DC /* Build configuration list for PBXProject "Magic 8 Ball" */ = { 506 | isa = XCConfigurationList; 507 | buildConfigurations = ( 508 | 697DEE1321F50E0700A4D6DC /* Debug */, 509 | 697DEE1421F50E0700A4D6DC /* Release */, 510 | ); 511 | defaultConfigurationIsVisible = 0; 512 | defaultConfigurationName = Release; 513 | }; 514 | 697DEE1521F50E0700A4D6DC /* Build configuration list for PBXNativeTarget "Magic 8 Ball" */ = { 515 | isa = XCConfigurationList; 516 | buildConfigurations = ( 517 | 697DEE1621F50E0700A4D6DC /* Debug */, 518 | 697DEE1721F50E0700A4D6DC /* Release */, 519 | ); 520 | defaultConfigurationIsVisible = 0; 521 | defaultConfigurationName = Release; 522 | }; 523 | /* End XCConfigurationList section */ 524 | }; 525 | rootObject = 697DEDFF21F50E0600A4D6DC /* Project object */; 526 | } 527 | -------------------------------------------------------------------------------- /Magic 8 Ball.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Magic 8 Ball.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Magic 8 Ball/AppController.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 aronskaya (Julia Vashchenko) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import Foundation 26 | 27 | class AppController { 28 | 29 | private var connection: NSXPCConnection? 30 | private var service: MagicServiceProtocol? 31 | 32 | func start() { 33 | connect() 34 | } 35 | 36 | private func connect() { 37 | connection = NSXPCConnection(serviceName: kServiceName) 38 | connection?.remoteObjectInterface = NSXPCInterface(with: MagicServiceProtocol.self) 39 | 40 | connection?.invalidationHandler = { NSLog("Connection did invalidate") } 41 | connection?.interruptionHandler = { NSLog("Connection did interrupt") } 42 | 43 | connection?.resume() 44 | service = self.connection?.remoteObjectProxyWithErrorHandler({ (error) in 45 | NSLog("Error: description: \(error as NSError)") 46 | }) as? MagicServiceProtocol 47 | } 48 | } 49 | 50 | extension AppController { 51 | func getDecision(withReply decisionHandler: @escaping (String) -> ()) { 52 | service?.getDecision(replyBlock: { (decision) in 53 | decisionHandler(decision) 54 | }) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Magic 8 Ball/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 aronskaya (Julia Vashchenko) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import AppKit 26 | 27 | @NSApplicationMain 28 | class AppDelegate: NSObject, NSApplicationDelegate { 29 | 30 | @IBOutlet private weak var window: NSWindow! 31 | @IBOutlet private weak var replyLabel: NSTextField! 32 | 33 | private let appController = AppController() 34 | 35 | func applicationDidFinishLaunching(_ notification: Notification) { 36 | appController.start() 37 | } 38 | 39 | @IBAction private func getAnswerButtonPressed(_ sender: Any) { 40 | self.window.shake() 41 | appController.getDecision { (decision) in 42 | // reply blocks are called on arbitrary thread, so we need to 43 | // reroute the call to main thread in order to update UI 44 | DispatchQueue.main.async { 45 | self.replyLabel.stringValue = decision 46 | } 47 | } 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Magic 8 Ball/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /Magic 8 Ball/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Magic 8 Ball/Base.lproj/MainMenu.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | Default 540 | 541 | 542 | 543 | 544 | 545 | 546 | Left to Right 547 | 548 | 549 | 550 | 551 | 552 | 553 | Right to Left 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | Default 565 | 566 | 567 | 568 | 569 | 570 | 571 | Left to Right 572 | 573 | 574 | 575 | 576 | 577 | 578 | Right to Left 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | -------------------------------------------------------------------------------- /Magic 8 Ball/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | Copyright © 2019 Julia Vashchenko. All rights reserved. 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /Magic 8 Ball/Magic 8 Ball.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Magic 8 Ball/NSWindow+Shaking.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 aronskaya (Julia Vashchenko) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import AppKit 26 | 27 | extension NSWindow { 28 | 29 | func shake() { 30 | let numberOfShakes = 6 31 | let durationOfShake = 0.25 32 | let vigourOfShake : CGFloat = 0.03 33 | 34 | let frame : CGRect = self.frame 35 | let shakeAnimation :CAKeyframeAnimation = CAKeyframeAnimation() 36 | 37 | let shakePath = CGMutablePath() 38 | shakePath.move(to: CGPoint(x: frame.minX, y: frame.minY)) 39 | 40 | for _ in 0.. 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | MagicXPCService 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | XPC! 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | NSHumanReadableCopyright 24 | Copyright © 2019 Julia Vashchenko. All rights reserved. 25 | XPCService 26 | 27 | ServiceType 28 | Application 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /MagicXPCService/ListenerDelegate.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 aronskaya (Julia Vashchenko) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import Foundation 26 | 27 | class ListenerDelegate: NSObject, NSXPCListenerDelegate { 28 | 29 | func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool { 30 | newConnection.exportedInterface = NSXPCInterface(with: MagicServiceProtocol.self) 31 | newConnection.exportedObject = MagicXPCService() 32 | 33 | newConnection.invalidationHandler = { NSLog("Connection did invalidate") } 34 | newConnection.interruptionHandler = { NSLog("Connection did interrupt") } 35 | 36 | newConnection.resume() 37 | 38 | return true; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /MagicXPCService/MagicXPCService.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /MagicXPCService/MagicXPCService.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 aronskaya (Julia Vashchenko) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import Foundation 26 | 27 | class MagicXPCService: NSObject, MagicServiceProtocol { 28 | let decisions = [ 29 | "It is certain", 30 | "It is decidedly so", 31 | "Without a doubt", 32 | "Yes - definitely", 33 | "You may rely on it", 34 | "As I see it, yes", 35 | "Most likely", 36 | "Outlook good", 37 | "Yes", 38 | "Signs point to yes", 39 | "Reply hazy, try again", 40 | "Ask again later", 41 | "Better not tell you now", 42 | "Cannot predict now", 43 | "Concentrate and ask again", 44 | "Don't count on it", 45 | "My reply is no", 46 | "My sources say no", 47 | "Outlook not so good", 48 | "Very doubtful"] 49 | 50 | @objc func getDecision(replyBlock: @escaping DecisionReplyBlock) { 51 | replyBlock(decisions.randomElement()!) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /MagicXPCService/main.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 aronskaya (Julia Vashchenko) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import Foundation 26 | 27 | NSLog("Magic XPC Service has started") 28 | 29 | let listener = NSXPCListener.service() 30 | let listenerDelegate = ListenerDelegate() 31 | 32 | listener.delegate = listenerDelegate 33 | 34 | listener.resume() 35 | 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Application with XPC Service and communication via XPC 2 | 3 | **Magic 8 Ball** is a sample app, that imitates the [Magic 8 Ball](https://www.imdb.com/title/tt0165832/mediaviewer/rm1258372352) best known from the 'Interstate 60: Episodes of the Road' movie. 4 | The application is intentionally simplified in order to serve as a working example for everyone, who wants to figure out how XPC Services work. 5 | 6 | The XPC Service is called **MagicXPCService**, and this is where we get the answers to out question from. 7 | 8 | Both the main UI app and the XPC Service are sandboxed. 9 | 10 | License: MIT. 11 | 12 | --------------------------------------------------------------------------------