Skip to content

Instantly share code, notes, and snippets.

View shishirthedev's full-sized avatar

Ahidul Islam shishirthedev

View GitHub Profile
extension String{
var length : Int {
return self.count
}
func replace(target: String, withString: String) -> String {
return self.replacingOccurrences(of: target, with: withString)
}
import UIKit
import Foundation
public class AlertService {
private init() {}
public static let shared = AlertService()
import UIKit
@IBDesignable class RoundButton: UIButton {
override func layoutSubviews() {
super.layoutSubviews()
updateCornerRadius()
}
import UIKit
class RoundImage: UIImageView {
@IBInspectable var cornerRadius:CGFloat = 0{
didSet{
self.layer.cornerRadius = cornerRadius
}
}
import UIKit
@IBDesignable class CardView: UIView {
@IBInspectable var cornerradius:CGFloat = 4
@IBInspectable var shadowOffsetWidth:CGFloat = 0
@IBInspectable var shadowOffsetHeight:CGFloat = 3
// String Extensions to encode/decode to Base64, capitalized first character.....
extension String{
// Decode String from Base64
func fromBase64() -> String? {
guard let data = Data(base64Encoded: self) else {
return nil
}
return String(data: data, encoding: .utf8)
import Foundation
import Alamofire
class Connectivity {
class var isConnectedToInternet: Bool {
return NetworkReachabilityManager()!.isReachable
}
}
import UIKit
import AVFoundation
class ScanQRCodeViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
var videoPreviewLayer: AVCaptureVideoPreviewLayer!
var captureSession: AVCaptureSession!
@IBOutlet weak var viewPreview: UIView!
override func viewDidLoad() {
func showActionSheet(title:String?,
titleColor: UIColor = UIColor.black,
message: String?,
messageColor: UIColor = UIColor.gray,
backgroundColor: UIColor = UIColor.white){
guard let message = message else { return }
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
extension UIView {
func displayToast(_ message : String) {
guard let delegate = UIApplication.shared.delegate as? AppDelegate, let window = delegate.window else {
return
}
if let toast = window.subviews.first(where: { $0 is UILabel && $0.tag == -1001 }) {
toast.removeFromSuperview()