Skip to content

Instantly share code, notes, and snippets.

View macbaszii's full-sized avatar
🏠
Working from home

iMacbaszii macbaszii

🏠
Working from home
View GitHub Profile
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,
private func waitForElementToAppear(element: XCUIElement) {
let existsPredicate = NSPredicate(format: "exists == true")
expectationForPredicate(existsPredicate,
evaluatedWithObject: element, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)
}
let element = app.buttons["Spike!"]
let existsPredicate = NSPredicate(format: "exists == true")
expectationForPredicate(existsPredicate,
evaluatedWithObject: element, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)
use_frameworks!
def shared_pods
pod 'AFNetworking', '~> 2.0.0'
pod 'MMWormhole'
end
target 'My App' do
platform :ios, '9.0'
pod 'Mantle'
"platforms": {
"iOS": "7.0",
"watchos": "2.0"
}
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]
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)
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 {
enum PurchaseError: ErrorType {
case OutOfStockItem
case InsufficientFund
case OtherError(message: String)
}
- (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