Skip to content

Instantly share code, notes, and snippets.

View Yoloabdo's full-sized avatar
:octocat:
Building another UIViewController

Abdoelrhman Yoloabdo

:octocat:
Building another UIViewController
View GitHub Profile
struct LoginRequestCommand: Command {
let id: String
let password: String
var completion: CallResponse<User>
init(_ id: String, password: String, completion: CallResponse<User>) {
self.id = id
self.password = password
self.completion = completion
struct LoginDetailsValidator: Command {
let email: String
let password: String
init(_ email: String, _ pass: String){
self.email = email
password = pass
}
// confirming to the protocol
func execute() throws {
class LoginViewController: UIViewController {
@IBOutlet weak var emailTextFeild: UITextField!
@IBOutlet weak var passwordTextFeild: UITextField!
@IBAction func userDidTapLogin(_ sender: UIButton) {
// validate user inputs
guard let email = emailTextFeild.text, !email.isEmpty else {
@Yoloabdo
Yoloabdo / VerificationPlaygroud.playground
Created November 2, 2018 17:03
verifying user inputs in Login/register view controllers
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
var usernameTextfield = UITextField()
var userPasswordTextfield = UITextField()
@Yoloabdo
Yoloabdo / Podfile
Created September 23, 2018 11:04
pod install for different swift version
post_install do |installer|
#setting all pods to 4.1
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.1'
end
end
#some libs uses the old version 4 only.
@Yoloabdo
Yoloabdo / SearchViewController
Created August 13, 2018 01:13
Throttling Searchbar ios swift
class SearchViewController: UIViewController, UISearchBarDelegate {
// We keep track of the pending work item as a property
private var pendingRequestWorkItem: DispatchWorkItem?
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
// Cancel the currently pending item
pendingRequestWorkItem?.cancel()
// Wrap our request in a work item
let requestWorkItem = DispatchWorkItem { [weak self] in
func ShowPayfort(controller: PayFortController, with order: ScanOrder, token sdkToken: String) {
let user = UserManager.shared.currentUserInfo
let request = NSMutableDictionary()
// Payfort api :Remember - Before sending the amount value of any transaction
// you have to multiply the value with the currency decimal code according to ISO code 3.
let updatedAmount: Float = Float(order.orderTotalSar! * 100)
request.setValue(updatedAmount, forKey: "amount")
request.setValue("PURCHASE", forKey: "command")//PURCHASE - AUTHORIZATION
request.setValue("SAR", forKey: "currency")
func proceedPayfort(with order: ScanOrder) {
guard let payFortController = PayFortController(enviroment: KPayFortEnviromentSandBox) else { return }
PayFortCredintials.development(udid: payFortController.getUDID()!).send(PayfortResponse.self) { (results) in
switch results {
case .success(let key):
if let token = key.sdkToken {
self.ShowPayfort(controller: payFortController, with: order, token: token)
}else {
struct Encryption {
static func sha256Hex(string: String) -> String? {
guard let messageData = string.data(using: String.Encoding.utf8) else { return nil }
var digestData = Data(count: Int(CC_SHA256_DIGEST_LENGTH))
_ = digestData.withUnsafeMutableBytes {digestBytes in
messageData.withUnsafeBytes {messageBytes in
CC_SHA256(messageBytes, CC_LONG(messageData.count), digestBytes)
}
@Yoloabdo
Yoloabdo / PayFortRequest
Last active November 4, 2018 00:13
An enum to hold your payfort payment info
enum PayFortCredintials {
case development(udid: String)
case production(udid: String)
var merchantId: String {
switch self {
case .development:
return "dfadf23"
default:
return "dsafq34r"