class MyAppCantFunctionUnlessBothPropertiesAreBloodyPresent {
var cloudId: String?
var apnsToken: String?
func pleaseJustSendThisShitToMyServerSoICanBeDoneWith() {
guard let cloudId = self.cloudId, apnsToken = self.apnsToken else {
print(“Sighs, nope not ready yet, we’re all probably waiting for that blaady apns token again")
return
}
print(“what took you two so long? Let’s make that request to igors server now")
This file contains 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
class ApiManager { | |
class func GET( | |
URLString: URLStringConvertible, | |
parameters: [String : AnyObject]? = nil, | |
encoding: ParameterEncoding? = .URL, | |
headers: [String : String]? = nil, | |
completionHandler: CompletionHandlerType | |
){ | |
alamofireManager().request(.GET, URLString, parameters: parameters, encoding: encoding!, headers: headers) | |
.validate() |
This file contains 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
// | |
// HasDisposeBag.swift | |
// | |
// Created by Pavan Kataria 26/09/2017 | |
// Copyright © 2017 Pavan Kataria. All rights reserved. | |
protocol HasDisposeBag { | |
var disposeBag: DisposeBag { get } | |
} | |
private struct AssociatedKeys { |
This file contains 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
import Foundation | |
import UIKit | |
public protocol CellRepresentable { | |
static func registerCell(tableView: UITableView) | |
func dequeueCell(tableView: UITableView, indexPath: IndexPath) -> UITableViewCell | |
func cellSelected(_ indexPath: IndexPath) | |
} | |
//MARK: - Default Implementation |
This file contains 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 processInput(_ stringNumber: String?) -> Int? { | |
guard let unwrappedStringNumber = stringNumber { | |
return nil | |
} | |
return Int(unwrappedStringNumber) | |
} |
This file contains 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 processInput(_ stringNumber: String?) -> Int? { | |
return stringNumber.flatMap { Int($0) } | |
} |
This file contains 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
// In the flatmap method it would look something like this | |
switch self { | |
case .some(let unwrapped): | |
return transform(unwrappedValue) | |
case .none: | |
return nil | |
} |
This file contains 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 balanceToConvert: String? | |
... | |
if let inputEntry = balance, inputEntry.sign == .negative { | |
balanceToConvert = Int(inputEntry.input) // Can return nil | |
.flatMap(Int.init) // Convert to Int if not nil | |
.flatMap { $0 * -1 } // flip sign if not nil | |
.flatMap(String.init) // convert back to String if not nil | |
} | |
... |
OlderNewer