This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private func waitForElementToAppear(element: XCUIElement, | |
| file: String = __FILE__, line: UInt = __LINE__) { | |
| let existsPredicate = NSPredicate(format: "exists == true") | |
| expectationForPredicate(existsPredicate, | |
| evaluatedWithObject: element, handler: nil) | |
| waitForExpectationsWithTimeout(5) { (error) -> Void in | |
| if (error != nil) { | |
| let message = "Failed to find \(element) after 5 seconds." | |
| self.recordFailureWithDescription(message, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private func waitForElementToAppear(element: XCUIElement) { | |
| let existsPredicate = NSPredicate(format: "exists == true") | |
| expectationForPredicate(existsPredicate, | |
| evaluatedWithObject: element, handler: nil) | |
| waitForExpectationsWithTimeout(5, handler: nil) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let element = app.buttons["Spike!"] | |
| let existsPredicate = NSPredicate(format: "exists == true") | |
| expectationForPredicate(existsPredicate, | |
| evaluatedWithObject: element, handler: nil) | |
| waitForExpectationsWithTimeout(5, handler: nil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use_frameworks! | |
| def shared_pods | |
| pod 'AFNetworking', '~> 2.0.0' | |
| pod 'MMWormhole' | |
| end | |
| target 'My App' do | |
| platform :ios, '9.0' | |
| pod 'Mantle' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "platforms": { | |
| "iOS": "7.0", | |
| "watchos": "2.0" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Process: Xcode [6015] | |
| Path: /Applications/Xcode.app/Contents/MacOS/Xcode | |
| Identifier: com.apple.dt.Xcode | |
| Version: 7.0.1 (8228) | |
| Build Info: IDEFrameworks-8228000000000000~5 | |
| App Item ID: 497799835 | |
| App External ID: 813434267 | |
| Code Type: X86-64 (Native) | |
| Parent Process: ??? [1] | |
| Responsible: Xcode [6015] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| do { | |
| try canPurchaseItem(specificItem, forUser: specificUser) | |
| } catch PurchaseError.OutOfStockItem { | |
| print("The Item is out of stock") | |
| } catch PurchaseError.InsufficientFunds { | |
| print("Your money is insufficient to buy this item") | |
| } | |
| // In case that you make sure the function always doesn't throw the error | |
| try! canPurchaseItem(specificItem, forUser: specificUser) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func canPurchaseItem(item: Item, forUser user: User) throws { | |
| let filtered = allItems.filter { (item: Item) -> Bool in | |
| return item === item; | |
| } | |
| if filtered.count == 0 { | |
| throw PurchaseError.OutOfStockItem | |
| } | |
| if user.money - item.price < 0 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum PurchaseError: ErrorType { | |
| case OutOfStockItem | |
| case InsufficientFund | |
| case OtherError(message: String) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (BOOL)canPurchaseItem:(Item *)item forUser:(User *)user withError:(NSError **)error { | |
| if ([self.items indexOfObject:item] == NSNotFound) { | |
| error = [NSError errorWithDomain:StoreErrorDomain | |
| code:PurchaseOutOfStockItemCode | |
| userInfo:@{ NSLocalizedDescriptionKey: @"Item is out of stock" }]; | |
| return NO; | |
| } | |
| if (user.money - item.price < 0) { | |
| error = [NSError errorWithDomain:StoreErrorDomain |