Skip to content

Instantly share code, notes, and snippets.

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

Fitzgerald Afful FitzAfful

🏠
Working from home
View GitHub Profile
@FitzAfful
FitzAfful / autocompleteError.txt
Created August 15, 2018 19:59
Description of Error in using PlaceAutoComplete Builder in Android
// call Google Places Autocomplete
try {
AutocompleteFilter autocompleteFilter = new AutocompleteFilter.Builder()
.setTypeFilter(Place.TYPE_COUNTRY)
.setCountry("GH")
.build();
Intent intent =
new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
.setFilter(autocompleteFilter)
.build(AddressActivity.this);
@FitzAfful
FitzAfful / AppDelegate
Created January 14, 2019 12:03
Lock all other screens and only rotate one controller.
var orientationLock = UIInterfaceOrientationMask.portrait
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return self.orientationLock
}
struct AppUtility {
static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.orientationLock = orientation
@FitzAfful
FitzAfful / FirstFruitsViewController.swift
Last active June 10, 2019 22:13
Gist to show benefits of Extensions in Swift
import UIKit
class FirstFruitsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
}
import Foundation
import Alamofire
public class APIManager {
private let manager: Session
init(manager: Session = Session.default) {
self.manager = manager
@FitzAfful
FitzAfful / Observable.swift
Created April 17, 2020 23:29
Observable is a generic class that helps you to bind your ViewModel to your View Controller
class Observable<T> {
var value: T {
didSet {
listener?(value)
}
}
private var listener: ((T) -> Void)?
import Foundation
import Alamofire
protocol ObservableViewModelProtocol {
func fetchEmployees()
func setError(_ message: String)
var employees: Observable<[Employee]> { get set } //1
var errorMessage: Observable<String?> { get set }
var error: Observable<Bool> { get set }
}
import Foundation
open class EventBus {
struct Static {
static let instance = EventBus()
static let queue = DispatchQueue(label: "EventBus", attributes: [])
}
import Foundation
class EmployeesEvent: NSObject {
var error: Bool
var errorMessage: String?
var employees: [Employee]?
init(error: Bool, errorMessage: String? = nil, employees: [Employee]? = nil) {
self.error = error
self.errorMessage = errorMessage
func callEvent() {
//Post Event (Publish Event)
EventBus.post("fetchEmployees", sender: EmployeesEvent(error: error, errorMessage: errorMessage, employees: employees))
}
func setupEventBusSubscriber() {
_ = EventBus.onMainThread(self, name: "fetchEmployees") { result in
if let event = result!.object as? EmployeesEvent {
if event.employees != nil {
self.showTableView()
} else if let message = event.errorMessage {
self.showAlert(title: "Error", message: message)
}
}
}