Skip to content

Instantly share code, notes, and snippets.

View hemangshah's full-sized avatar
🎯
Focusing

Hemang hemangshah

🎯
Focusing
  • Stockholm, Stockholm County, Sweden
View GitHub Profile
@hemangshah
hemangshah / LoginErrorHandling.playground
Created December 24, 2018 06:51
Trying to implement the best way to handle custom errors through in a login flow (as an example).
import UIKit
// ---- [LoginManager.swift] ---- starts
enum LoginError: Error {
case minUserNameLength(String), minPasswordLength(String), invalidUserName(String), invalidPassword(String)
}
enum LoginResult {
case result([String: Any])
}
@hemangshah
hemangshah / AppDelegate.swift
Created December 12, 2018 11:05
Managing Local & Remote Notifications from different classes
// [START receive_message]
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print full message.
print(userInfo)
@hemangshah
hemangshah / NetworkMonitor.swift
Created April 15, 2018 08:17
NetworkMonitor can be used to check for the Internet Connection
import UIKit
import Reachability
class NetworkMonitor {
static let shared = NetworkMonitor()
internal var isNetworkAvailable : Bool {
get {
return networkStatus != .none
}
}
@hemangshah
hemangshah / MyLabel.swift
Created August 24, 2017 09:44
Observe Text changes in UILabel in Swift
class MyLabel: UILabel {
var textWillChange:((_ oldText: String?)->())? = nil
var textDidChange:((_ newText: String?)->())? = nil
override var text: String? {
willSet {
if textWillChange != nil {
textWillChange!(self.text)
}
}
didSet {
@hemangshah
hemangshah / StackPlayground.playground
Last active August 10, 2017 08:59
This is the demonstration of Stack in Swift. I have used the default functions to handle the Stack operations.
//: Playground - noun: a place where people can play
import Foundation
class Stack {
static let list = Stack.init()
private var items = Array<Any>()
internal var limit = 5
//MARK: Push