Skip to content

Instantly share code, notes, and snippets.

View SulemanAli303's full-sized avatar

Suleman Ali SulemanAli303

View GitHub Profile
import Foundation
import Alamofire
class Connectivity {
class func isConnectedToInternet() ->Bool {
return NetworkReachabilityManager()!.isReachable
}
}
extension UIStoryboard {
class func viewController(identifier: String) -> UIViewController {
return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: identifier)
}
}
@SulemanAli303
SulemanAli303 / IQKeyboardManager.swift
Created November 30, 2020 09:02 — forked from fakiho/IQKeyboardManager.swift
Keyboard dimiss with done button
import IQKeyboardManagerSwift
{
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
IQKeyboardManager.sharedManager().enable = true
}
}
@SulemanAli303
SulemanAli303 / UIImage.swift
Created November 30, 2020 09:02 — forked from fakiho/UIImage.swift
create a base64 string image
extension UIImage {
public func base64(format: ImageFormat) -> String? {
var imageData: Data?
switch format {
case .png: imageData = UIImagePNGRepresentation(self)
case .jpeg(let compression): imageData = UIImageJPEGRepresentation(self, compression)
}
return imageData?.base64EncodedString()
}
@SulemanAli303
SulemanAli303 / Date.swift
Created November 30, 2020 09:02 — forked from fakiho/Date.swift
return TimeSpan
extension Date {
var ticks: UInt64 {
return UInt64((self.timeIntervalSince1970 ) * 1000)
}
}
@SulemanAli303
SulemanAli303 / DateCollectionViewCell.swift
Created November 30, 2020 09:01 — forked from fakiho/DateCollectionViewCell.swift
Create a DateTime Picker Custom
//
// DateCollectionViewCell.swift
// DateTimePicker
//
// Created by Fakiho on 01/01/18.
// Copyright © 2018 fakiho.com </>. All rights reserved.
//
import UIKit
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
// Should remove all subsequent view controllers from memory.
appDelegate.window?.rootViewController?.dismiss(animated: true, completion: nil)
// Set the root view controller to a new instance of the sign in view controller.
appDelegate.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "animated")
extension UIViewController {
func setupViewResizerOnKeyboardShown() {
NotificationCenter.default.addObserver(self,
selector: #selector(UIViewController.keyboardWillShowForResizing),
name: Notification.Name.UIKeyboardWillShow,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(UIViewController.keyboardWillHideForResizing),
name: Notification.Name.UIKeyboardWillHide,
object: nil)
func showNoConnectionAlert(_ messgae: String = "No connection, please make sure you have an internet access", _ Title: String = "No Connection", action: (() -> Void)?){
OperationQueue.main.addOperation {
let alert = UIAlertController(title: Title, message: messgae, preferredStyle: .alert)
let actionLocalized = NSLocalizedString("Settings", comment: "")
let settingAction: UIAlertAction = UIAlertAction(title: actionLocalized, style: .default) { actions -> Void in action?()}
alert.addAction(settingAction)
UIApplication.topViewController()?.present(alert, animated: true, completion: nil)
}
}
class exapmpe: UIViewController,UIPopoverPresentationControllerDelegate {
@IBAction func pressMe(_sender : UIButton){
let popController = UIStoryboard(name: "StoryBoardMain", bundle: nil).instantiateViewController(withIdentifier: "example")
popController.modalPresentationStyle = UIModalPresentationStyle.popover
popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up
popController.popoverPresentationController?.delegate = self
popController.popoverPresentationController?.sourceView = sender
popController.popoverPresentationController?.sourceRect = sender.bounds
self.present(popController, animated: true, completion: nil)