├── README.md └── ShortCode ├── ShortCode.xcodeproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── pulkit.xcuserdatad │ │ └── UserInterfaceState.xcuserstate ├── xcuserdata │ └── pulkit.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── ShortCode.xcscheme └── project.pbxproj └── ShortCode ├── ViewController.swift ├── Model └── UserClass.swift ├── Libs ├── CustomImageView │ └── CustomImageView.swift ├── Theme.swift ├── ShowDescriptionPopup.swift ├── DLCategory+Extention.swift └── DateValidator.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Info.plist ├── Base.lproj ├── Main.storyboard └── LaunchScreen.storyboard ├── Required ├── AllConstants.swift ├── QueueManager │ └── QueueManager.swift ├── AppExtension │ └── UIImageExtension.swift └── ImagePicker │ └── ImagePickerVC.swift └── AppDelegate.swift /README.md: -------------------------------------------------------------------------------- 1 | # Codes 2 | Generic Codes for ease of developement 3 | -------------------------------------------------------------------------------- /ShortCode/ShortCode.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ShortCode/ShortCode.xcodeproj/project.xcworkspace/xcuserdata/pulkit.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vorapulkit/ShortCodes/HEAD/ShortCode/ShortCode.xcodeproj/project.xcworkspace/xcuserdata/pulkit.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ShortCode/ShortCode/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ShortCode 4 | // 5 | // Created by Pulkit on 6/17/17. 6 | // Copyright © 2017 Pulkeet. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /ShortCode/ShortCode.xcodeproj/xcuserdata/pulkit.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ShortCode.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0237FA7B1EF547B800AFBB8F 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Model/UserClass.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UserClass.swift 3 | // Structure 4 | // 5 | // Created by Pulkit on 6/17/17. 6 | // Copyright © 2017 Pulkit. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class UserClass: NSObject { 12 | 13 | var firstName = "" 14 | var lastName = "" 15 | var age = 0; 16 | 17 | 18 | 19 | init(_firstName : String?,_lastName : String?,_age : Int) { 20 | 21 | firstName = _firstName! 22 | lastName = _lastName! 23 | age = _age 24 | } 25 | 26 | } 27 | 28 | extension UserClass{ 29 | 30 | func fullName()->String{ 31 | return firstName + "" + lastName 32 | } 33 | 34 | func ageType()->String{ 35 | 36 | switch age { 37 | case 0...2: 38 | return "Baby" 39 | case 2...12: 40 | return "Child" 41 | case 12...29: 42 | return "Teenage" 43 | case let x where x > 65: 44 | return "Elder" 45 | default: 46 | return "Normal" 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Libs/CustomImageView/CustomImageView.swift: -------------------------------------------------------------------------------- 1 | 2 | 3 | import UIKit 4 | 5 | class CustomImageView: UIImageView { 6 | 7 | /* 8 | // Only override draw() if you perform custom drawing. 9 | // An empty implementation adversely affects performance during animation. 10 | override func draw(_ rect: CGRect) { 11 | // Drawing code 12 | } 13 | */ 14 | var imageURL: String? 15 | var btnReTry: UIButton? 16 | 17 | convenience init(imgURL : String?) { 18 | self.init() 19 | addTryButton() 20 | 21 | if imgURL != nil { 22 | self.imageURL = imgURL 23 | self.startDownlodingImage() 24 | } 25 | 26 | } 27 | 28 | 29 | private func addTryButton(){ 30 | btnReTry = UIButton() 31 | btnReTry?.translatesAutoresizingMaskIntoConstraints = false; 32 | btnReTry?.addTarget(self, action: #selector(self.restartDownlodingImage), for: .touchUpInside) 33 | btnReTry?.backgroundColor = UIColor.red 34 | self.addSubview(btnReTry!) 35 | 36 | } 37 | 38 | @objc private func restartDownlodingImage(){ 39 | 40 | } 41 | 42 | private func startDownlodingImage(){ 43 | 44 | } 45 | 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /ShortCode/ShortCode/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Required/AllConstants.swift: -------------------------------------------------------------------------------- 1 | 2 | 3 | import UIKit 4 | 5 | // MARK:- SINGLETON classes 6 | 7 | let QueueManagerClass : QueueManager = QueueManager.shared() 8 | 9 | 10 | //let APPDELEGATE = (UIApplication.shared.delegate as! AppDelegate) 11 | //let DBSINGLETON : DBSingleton = DBSingleton.sharedInstance 12 | 13 | // MARK:- SCREEN SIZE 14 | struct ScreenSize 15 | { 16 | static let SCREEN_WIDTH = UIScreen.main.bounds.size.width 17 | static let SCREEN_HEIGHT = UIScreen.main.bounds.size.height 18 | static let SCREEN_MAX_LENGTH = max(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT) 19 | static let SCREEN_MIN_LENGTH = min(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT) 20 | } 21 | // MARK:- DEVICE TYPE 22 | struct DeviceType 23 | { 24 | static let IS_IPHONE_4_OR_LESS = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH < 568.0 25 | static let IS_IPHONE_5 = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 568.0 26 | static let IS_IPHONE_6 = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 667.0 27 | static let IS_IPHONE_6_PLUS = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 736.0 28 | static let IS_IPAD = UIDevice.current.userInterfaceIdiom == .pad && ScreenSize.SCREEN_MAX_LENGTH == 1024.0 29 | } 30 | 31 | //MARK: DB NAME JM 32 | func getDataBaseName()->String 33 | { 34 | return "AppDBName.sqlite" 35 | } 36 | 37 | // MARK: Set object in NSuserDefault :- 38 | func kNSuserDefault(_ value:AnyObject, key:NSString){ 39 | UserDefaults.standard.set(value, forKey: key as String ) 40 | UserDefaults.standard.synchronize() 41 | } 42 | 43 | func kNSUserDefaultGetValue(_ key:String?)->AnyObject?{ 44 | return UserDefaults.standard.value(forKey: key!) as AnyObject? 45 | 46 | } 47 | 48 | func kNSUserDefaultRemoveValueForkey(_ key:String?){ 49 | UserDefaults.standard.removeObject(forKey: key!) 50 | UserDefaults.standard.synchronize() 51 | } 52 | 53 | //MARK: - Read Localozed File 54 | func read_Localizable(_ title:String)->String{ 55 | return NSLocalizedString(title, comment: "") 56 | } 57 | 58 | 59 | // For WhiteSpace 60 | func removeWhiteSpace(_ string : String) -> String 61 | { 62 | return string.trimmingCharacters(in: CharacterSet.whitespaces) 63 | } 64 | 65 | func getDocumentDirectory() -> String { 66 | let paths: [Any] = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) 67 | let documentsDirectory: String? = (paths[0] as? String) 68 | return documentsDirectory! 69 | } 70 | 71 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Required/QueueManager/QueueManager.swift: -------------------------------------------------------------------------------- 1 | 2 | import UIKit 3 | 4 | enum QueueState : String { 5 | case ReadyToUse = "ReadyToUse" 6 | case OnHold = "OnHold" 7 | case Busy = "Busy" 8 | } 9 | 10 | 11 | let queueName = "CustomTestQueue" 12 | 13 | class QueueManager: NSObject { 14 | 15 | var customQueue : OperationQueue? 16 | var arrOperation : NSMutableArray? 17 | var queueState = QueueState.ReadyToUse.rawValue; 18 | 19 | class var sharedInstance:QueueManager { 20 | struct QueueManagerInstance { 21 | static let instance_new = QueueManager() 22 | } 23 | return QueueManagerInstance.instance_new 24 | } 25 | class func shared() -> QueueManager { 26 | return sharedInstance 27 | } 28 | //MARK: 29 | //MARK: Init 30 | func createQueue(){ 31 | //Create Queue if not exist 32 | if customQueue == nil { 33 | customQueue = OperationQueue() 34 | customQueue?.name = queueName; 35 | customQueue?.qualityOfService = .background; 36 | 37 | arrOperation = NSMutableArray() 38 | prepareQueue() 39 | } 40 | } 41 | 42 | //MARK: 43 | //MARK: Operation 44 | func addOprToQueue( operationBlock : @escaping ()->()) { 45 | 46 | let op = BlockOperation() 47 | op.qualityOfService = .background 48 | op.addExecutionBlock { 49 | // print("executing" , op.name!) 50 | // sleep(3) 51 | operationBlock() 52 | } 53 | op.completionBlock = { 54 | // print("complete obj",op.name!) 55 | } 56 | 57 | arrOperation?.add(op) 58 | 59 | } 60 | 61 | func startQueue(){ 62 | 63 | if queueState == QueueState.ReadyToUse.rawValue { 64 | queueState = QueueState.Busy.rawValue 65 | for cntr in 0..<(arrOperation?.count)! { 66 | let oprCurrent = arrOperation?[cntr] as! BlockOperation 67 | if oprCurrent.isExecuting {//if already in process then skip 68 | print("Queue is executing ",oprCurrent.name!) 69 | continue; 70 | } 71 | customQueue?.addOperations([oprCurrent], waitUntilFinished: true) 72 | if cntr < (arrOperation?.count)! - 1 { 73 | let operNext = arrOperation?[cntr + 1] as! Operation 74 | oprCurrent.addDependency(operNext) 75 | } 76 | 77 | } 78 | } 79 | 80 | 81 | 82 | } 83 | 84 | //MARK: 85 | //MARK: Support 86 | func cancelQueue(){ 87 | customQueue?.cancelAllOperations() 88 | prepareQueue() 89 | } 90 | 91 | func prepareQueue(){ 92 | queueState = QueueState.ReadyToUse.rawValue 93 | arrOperation?.removeAllObjects() 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Required/AppExtension /UIImageExtension.swift: -------------------------------------------------------------------------------- 1 | 2 | 3 | import UIKit 4 | import CoreGraphics 5 | 6 | /** 7 | Adds framework-related methods to `UIImage`. 8 | */ 9 | public extension UIImage { 10 | /// Returns a copy of the image, taking into account its orientation 11 | public var imgly_normalizedImage: UIImage { 12 | if imageOrientation == .up { 13 | return self 14 | } 15 | 16 | return imgly_normalizedImageOfSize(size: size) 17 | } 18 | 19 | /** 20 | Returns a rescaled copy of the image, taking into account its orientation 21 | 22 | - parameter size: The size of the rescaled image. 23 | 24 | - returns: The rescaled image. 25 | 26 | :discussion: The image will be scaled disproportionately if necessary to fit the bounds specified by the parameter. 27 | */ 28 | public func imgly_normalizedImageOfSize(size: CGSize) -> UIImage { 29 | UIGraphicsBeginImageContextWithOptions(size, false, scale) 30 | draw(in: CGRect(origin: CGPoint.zero, size: size)) 31 | let normalizedImage = UIGraphicsGetImageFromCurrentImageContext() 32 | UIGraphicsEndImageContext() 33 | return normalizedImage! 34 | } 35 | // 1200 36 | 37 | public func generateLowResolutionImage(maxLowResolutionSideLength:CGFloat) -> UIImage 38 | { 39 | let highResolutionImage = self 40 | let lowResolutionImage:UIImage; 41 | if highResolutionImage.size.width > maxLowResolutionSideLength || highResolutionImage.size.height > maxLowResolutionSideLength { 42 | let scale: CGFloat 43 | 44 | if(highResolutionImage.size.width > highResolutionImage.size.height) { 45 | scale = maxLowResolutionSideLength / highResolutionImage.size.width 46 | } else { 47 | scale = maxLowResolutionSideLength / highResolutionImage.size.height 48 | } 49 | 50 | let newWidth = CGFloat(roundf(Float(highResolutionImage.size.width) * Float(scale))) 51 | let newHeight = CGFloat(roundf(Float(highResolutionImage.size.height) * Float(scale))) 52 | 53 | lowResolutionImage = highResolutionImage.imgly_normalizedImageOfSize(size: CGSize(width: newWidth, height: newHeight)) 54 | } else { 55 | lowResolutionImage = highResolutionImage.imgly_normalizedImage 56 | } 57 | return lowResolutionImage; 58 | } 59 | } 60 | 61 | 62 | 63 | extension UIImageOrientation: CustomStringConvertible { 64 | public var description: String { 65 | switch self { 66 | case .up: return "Up" 67 | case .down: return "Down" 68 | case .left: return "Left" 69 | case .right: return "Right" 70 | case .upMirrored: return "UpMirrored" 71 | case .downMirrored: return "DownMirrored" 72 | case .leftMirrored: return "LeftMirrored" 73 | case .rightMirrored: return "RightMirrored" 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /ShortCode/ShortCode.xcodeproj/xcuserdata/pulkit.xcuserdatad/xcschemes/ShortCode.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ShortCode 4 | // 5 | // Created by Pulkit on 6/17/17. 6 | // Copyright © 2017 Pulkeet. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import UserNotifications 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate,UNUserNotificationCenterDelegate { 14 | 15 | var window: UIWindow? 16 | 17 | 18 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 19 | // Override point for customization after application launch. 20 | return true 21 | } 22 | 23 | func applicationWillResignActive(_ application: UIApplication) { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 26 | } 27 | 28 | func applicationDidEnterBackground(_ application: UIApplication) { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | func applicationWillEnterForeground(_ application: UIApplication) { 34 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | func applicationDidBecomeActive(_ application: UIApplication) { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | func applicationWillTerminate(_ application: UIApplication) { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | //MARK: FOR PUSH NOTIFICATION 46 | func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { 47 | 48 | let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)}) 49 | print("DEVICE TOKEN \(deviceTokenString)") 50 | } 51 | 52 | 53 | //CHECK & REGISTER FOR NOTIFICATION SERVICE 54 | private func pushNotificationService(_ application: UIApplication) 55 | { 56 | 57 | if #available(iOS 10.0, *) { 58 | 59 | let center = UNUserNotificationCenter.current() 60 | center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in 61 | 62 | // Enable or disable features based on authorization. 63 | if granted == true 64 | { 65 | //print("Allow") 66 | center.delegate = self 67 | application.registerForRemoteNotifications() 68 | } 69 | else{ 70 | print("Don't Allow") 71 | } 72 | } 73 | } 74 | else 75 | { 76 | let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) 77 | application.registerUserNotificationSettings(settings) 78 | application.registerForRemoteNotifications() 79 | } 80 | 81 | } 82 | 83 | 84 | //MARK: 85 | //MARK: Received Remote Notification 86 | 87 | func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { 88 | //handlePush(withUserInfo: userInfo["aps"] as! NSDictionary) 89 | completionHandler(.newData) 90 | } 91 | 92 | //MARK: 93 | //MARK: iOS 10 (Later) 94 | @available(iOS 10.0, *) 95 | func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { 96 | print(response.notification.request.content.userInfo) 97 | //let userInfo = response.notification.request.content.userInfo["aps"] as! NSDictionary 98 | //handlePush(withUserInfo: userInfo) 99 | completionHandler() 100 | } 101 | 102 | @available(iOS 10.0, *) 103 | func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { 104 | //let userInfo = notification.request.content.userInfo["aps"] as! NSDictionary 105 | //handlePush(withUserInfo: userInfo) 106 | completionHandler([.sound]) 107 | } 108 | 109 | 110 | 111 | 112 | } 113 | 114 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Libs/Theme.swift: -------------------------------------------------------------------------------- 1 | 2 | import Foundation 3 | import UIKit 4 | 5 | enum Color { 6 | 7 | case SeperatorColor 8 | case ThemeColor 9 | case Black 10 | case White 11 | case SearchBarBG 12 | case btnOrnage 13 | case lightGray 14 | case textGray 15 | case textDrakGray 16 | 17 | case custom(hexString: String, alpha: Double) 18 | 19 | func withAlpha(_ alpha: Double) -> UIColor { 20 | return self.value.withAlphaComponent(CGFloat(alpha)) 21 | } 22 | } 23 | 24 | extension Color { 25 | 26 | var value: UIColor { 27 | var instanceColor = UIColor.clear 28 | 29 | switch self { 30 | 31 | case .SeperatorColor: 32 | instanceColor = UIColor(hexString: "#CCCCCC") // 204 204 204 33 | 34 | case .ThemeColor: 35 | instanceColor = UIColor(hexString: "#216595") //33 101 149 36 | 37 | case .Black: 38 | instanceColor = UIColor.black 39 | 40 | case .White: 41 | instanceColor = UIColor.white 42 | 43 | case .btnOrnage: 44 | instanceColor = UIColor(hexString: "#F68A4A") // 246 138 74 45 | 46 | case .SearchBarBG: 47 | instanceColor = UIColor(hexString: "#DCDCDC") // 220 220 220 48 | 49 | case .lightGray: 50 | instanceColor = UIColor(hexString: "#F1F1F1") // 241 241 241 51 | 52 | case .textGray: 53 | instanceColor = UIColor(hexString: "#686868") // 104 104 104 54 | 55 | case .textDrakGray: 56 | instanceColor = UIColor(hexString: "#A8A8A8") // 168 168 168 57 | 58 | case .custom(let hexValue, let opacity): 59 | instanceColor = UIColor(hexString: hexValue).withAlphaComponent(CGFloat(opacity)) 60 | } 61 | return instanceColor 62 | } 63 | } 64 | 65 | extension UIColor { 66 | /** 67 | Creates an UIColor from HEX String in "#363636" format 68 | 69 | - parameter hexString: HEX String in "#363636" format 70 | 71 | - returns: UIColor from HexString 72 | */ 73 | convenience init(hexString: String) { 74 | 75 | let hexString: String = (hexString as NSString).trimmingCharacters(in: .whitespacesAndNewlines) 76 | let scanner = Scanner(string: hexString as String) 77 | 78 | if hexString.hasPrefix("#") { 79 | scanner.scanLocation = 1 80 | } 81 | 82 | var color: UInt32 = 0 83 | scanner.scanHexInt32(&color) 84 | 85 | let mask = 0x000000FF 86 | let r = Int(color >> 16) & mask 87 | let g = Int(color >> 8) & mask 88 | let b = Int(color) & mask 89 | 90 | let red = CGFloat(r) / 255.0 91 | let green = CGFloat(g) / 255.0 92 | let blue = CGFloat(b) / 255.0 93 | 94 | self.init(red:red, green:green, blue:blue, alpha:1) 95 | } 96 | } 97 | 98 | 99 | 100 | // Font 101 | 102 | struct Font { 103 | 104 | enum FontType { 105 | case custom(FontName) 106 | } 107 | 108 | enum FontSize { 109 | case standard(StandardSize) 110 | var value: CGFloat { 111 | switch self { 112 | case .standard(let size): 113 | return size.fontSize() 114 | } 115 | } 116 | } 117 | 118 | enum FontName: String { 119 | case Roboto_Light = "Roboto-Light" 120 | case Roboto_Regular = "Roboto-Regular" 121 | case Roboto_Medium = "Roboto-Medium" 122 | 123 | } 124 | 125 | enum StandardSize : Int{ 126 | case Extra2Small = 0 127 | case ExtraSmall = 1 128 | case Small = 2 129 | case RegularSmall = 3 130 | case Regular = 4 131 | case RegularLarge = 5 132 | case Large = 6 133 | case ExtraLarge = 7 134 | case Extra2Large = 8 135 | 136 | 137 | func fontSize()->CGFloat{ 138 | switch self{ 139 | // case .Extra2Small: 140 | // return getSizeForDeviceType(13.0, ipadFSize: 18.0, iphoneFSize: 10.0,iphone4SFSize: 9.0) 141 | // case .ExtraSmall: 142 | // return getSizeForDeviceType(16.0, ipadFSize: 21.0, iphoneFSize: 13.0,iphone4SFSize: 12.0) 143 | // case .Small: 144 | // return getSizeForDeviceType(17.0, ipadFSize: 22.0, iphoneFSize: 14.0,iphone4SFSize: 13.0); 145 | // case .Regular: 146 | // return getSizeForDeviceType(18.0, ipadFSize: 23.0, iphoneFSize: 15.0,iphone4SFSize: 14.0); 147 | // case .LargeSize: 148 | // return getSizeForDeviceType(20.0, ipadFSize: 25.0, iphoneFSize: 17.0,iphone4SFSize: 16.0); 149 | // case .ExtraLargeSize: 150 | // return getSizeForDeviceType(22.0, ipadFSize: 27.0, iphoneFSize: 19.0,iphone4SFSize: 18.0); 151 | // case .Extra2LargeSize: 152 | // return getSizeForDeviceType(24.0, ipadFSize: 29.0, iphoneFSize: 21.0,iphone4SFSize: 20.0); 153 | // case .Extra2XLargeSize: 154 | // return getSizeForDeviceType(28, ipadFSize: 33, iphoneFSize: 25,iphone4SFSize: 24); 155 | 156 | case .Extra2Small: 157 | return getSizeForDeviceType(13.0, ipadFSize: 18.0, iphoneFSize: 10.0,iphone4SFSize: 9.0) 158 | case .ExtraSmall: 159 | return getSizeForDeviceType(14.0, ipadFSize: 19.0, iphoneFSize: 11.0,iphone4SFSize: 10.0) 160 | case .Small: 161 | return getSizeForDeviceType(16.0, ipadFSize: 21.0, iphoneFSize: 13.0,iphone4SFSize: 12.0); 162 | case .RegularSmall: 163 | return getSizeForDeviceType(17.0, ipadFSize: 22.0, iphoneFSize: 14.0,iphone4SFSize: 13.0); 164 | case .Regular: 165 | return getSizeForDeviceType(18.0, ipadFSize: 23.0, iphoneFSize: 15.0,iphone4SFSize: 14.0); 166 | case .RegularLarge: 167 | return getSizeForDeviceType(20.0, ipadFSize: 25.0, iphoneFSize: 18.0,iphone4SFSize: 16.0); 168 | case .Large: 169 | return getSizeForDeviceType(23.0, ipadFSize: 28.0, iphoneFSize: 20.0,iphone4SFSize: 19.0); 170 | case .ExtraLarge: 171 | return getSizeForDeviceType(28.0, ipadFSize: 33.0, iphoneFSize: 25.0,iphone4SFSize: 23.0); 172 | case .Extra2Large: 173 | return getSizeForDeviceType(57.0, ipadFSize: 63.0, iphoneFSize: 55.0,iphone4SFSize: 54.0); 174 | 175 | } 176 | } 177 | 178 | } 179 | var type: FontType 180 | var size: FontSize 181 | init(_ type: FontType, size: FontSize) { 182 | self.type = type 183 | self.size = size 184 | } 185 | 186 | } 187 | // How to use: 188 | //Font(.custom(.GillSans_Regular), size: .standard(.Regular)).instance 189 | 190 | func getSizeForDeviceType(_ sixPlusFSize : CGFloat, ipadFSize : CGFloat, iphoneFSize : CGFloat,iphone4SFSize : CGFloat)->CGFloat 191 | { 192 | return DeviceType.IS_IPHONE_6_PLUS ? sixPlusFSize : (DeviceType.IS_IPAD ? ipadFSize : (DeviceType.IS_IPHONE_4_OR_LESS ? iphone4SFSize : iphoneFSize)) 193 | 194 | } 195 | 196 | extension Font { 197 | var instance: UIFont { 198 | var instanceFont: UIFont! 199 | switch type { 200 | 201 | case .custom(let fontName): 202 | guard let font = UIFont(name: fontName.rawValue, size: CGFloat(size.value)) else { 203 | fatalError("\(fontName.rawValue) font is not installed, make sure it added in Info.plist and logged with Utility.logAllAvailableFonts()") 204 | } 205 | instanceFont = font 206 | } 207 | return instanceFont 208 | } 209 | } 210 | 211 | 212 | 213 | 214 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Libs/ShowDescriptionPopup.swift: -------------------------------------------------------------------------------- 1 | 2 | 3 | import UIKit 4 | 5 | class ShowDescriptionPopup: UIView { 6 | /** Default SimpleSelection*/ 7 | // var selectionType : PopType = PopType.simpleSelect 8 | // var delegate : PopUpDelegate? 9 | var arrButtonTile : NSMutableArray = NSMutableArray() 10 | var baseView = UIView() 11 | var selction:Int? 12 | var arrSelectedOBJ = NSMutableArray() 13 | var popupArrowColor : UIColor! = UIColor.clear 14 | /** Defaul Font Raleway Regular And Size 15 */ 15 | 16 | required init?(coder aDecoder: NSCoder) { 17 | fatalError("init(coder:) has not been implemented") 18 | } 19 | 20 | init(descriptionText discription:String,toView temView : UIView,withFont font:UIFont,withColor popupColor:UIColor) { 21 | super.init(frame : ((UIApplication.shared.delegate as! AppDelegate).window?.frame)!) 22 | print(temView) 23 | self.popupArrowColor = popupColor 24 | 25 | //self.frame = CGRect(x: 0, y: 64, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height - (64 + (UIScreen.main.bounds.size.height * 0.07) )) 26 | (UIApplication.shared.delegate as! AppDelegate).window?.addSubview(self) 27 | self.translatesAutoresizingMaskIntoConstraints = false 28 | (UIApplication.shared.delegate as! AppDelegate).window?.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[self]|", options: [], metrics: nil, views: ["self" : self])) 29 | (UIApplication.shared.delegate as! AppDelegate).window?.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[self]|", options: [], metrics: nil, views: ["self" : self])) 30 | self.alpha = 0.01 31 | var topr = 2 32 | let bwidth = UIScreen.main.bounds.size.width * 0.23 33 | var bheight = discription.boundingRect(with: CGSize(width: bwidth, height: CGFloat.greatestFiniteMagnitude), options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil).size.height + 17 34 | 35 | if bheight > UIScreen.main.bounds.size.height * 0.4 { 36 | bheight = UIScreen.main.bounds.size.height * 0.4 37 | } 38 | var point = temView.superview!.convert(temView.center, to: nil) 39 | let c = point.x 40 | var displayPoint = CGPoint(x: bwidth/2 , y: point.y) //let displayPoint = CGPoint(x: point.x , y: point.y) 41 | 42 | point.y = point.y + (temView.frame.size.height / 2) + 11 43 | point.x = point.x - (bwidth / 2)// - 15 44 | //if (point.y + bheight) > UIScreen.main.bounds.size.height { 45 | point.y = point.y - temView.frame.size.height - bheight - 21 46 | topr = 2 47 | // } 48 | if (point.x + bwidth) > UIScreen.main.bounds.size.width { 49 | 50 | point.x = point.x - 10 - (((point.x + bwidth) - (UIScreen.main.bounds.size.width))) 51 | displayPoint.x = c - point.x 52 | } 53 | self.backgroundColor = UIColor.clear 54 | baseView.frame = CGRect(x: point.x, y: point.y, width: bwidth, height: bheight) 55 | baseView.layer.cornerRadius = 5 56 | baseView.backgroundColor = popupArrowColor 57 | self.addSubview(baseView) 58 | let shapeLayer = CAShapeLayer() 59 | let pat = UIBezierPath() 60 | point.x = point.x - 7 61 | pat.move(to: CGPoint(x: 5, y: 0)) 62 | 63 | pat.addQuadCurve(to: CGPoint(x:baseView.frame.size.width , y: 5), controlPoint: CGPoint(x: baseView.frame.size.width, y: 0)) 64 | pat.addLine(to: CGPoint(x: baseView.frame.size.width, y: baseView.frame.size.height - 5)) 65 | pat.addQuadCurve(to: CGPoint(x: baseView.frame.size.width - 5, y: baseView.frame.size.height), controlPoint: CGPoint(x: baseView.frame.size.width, y: baseView.frame.size.height)) 66 | if topr == 2 { 67 | pat.addLine(to: CGPoint(x: displayPoint.x + 5, y: baseView.frame.size.height)) 68 | pat.addLine(to: CGPoint(x: displayPoint.x , y: baseView.frame.size.height + 10)) 69 | pat.addLine(to: CGPoint(x: displayPoint.x - 5, y: baseView.frame.size.height)) 70 | pat.addLine(to: CGPoint(x: 5, y: baseView.frame.size.height)) 71 | } 72 | // else { 73 | // pat.addLine(to: CGPoint(x: 5, y: baseView.frame.size.height)) 74 | // } 75 | pat.addQuadCurve(to: CGPoint(x: 0, y: baseView.frame.size.height - 5), controlPoint: CGPoint(x: 0, y: baseView.frame.size.height)) 76 | pat.addLine(to: CGPoint(x: 0, y: 5)) 77 | pat.addQuadCurve(to: CGPoint(x: 5, y: 0), controlPoint: CGPoint(x: 0, y: 0)) 78 | pat.addLine(to: CGPoint(x: 5, y: 0)) 79 | 80 | shapeLayer.fillColor = popupArrowColor.cgColor 81 | shapeLayer.path = pat.cgPath 82 | shapeLayer.lineWidth = 1 83 | shapeLayer.strokeColor = popupArrowColor.withAlphaComponent(1.0).cgColor 84 | shapeLayer.cornerRadius = 35 85 | shapeLayer.shadowOpacity = 0.3 86 | shapeLayer.shadowOffset = CGSize(width: -0.02,height: -2.5) 87 | //shapeLayer.shadowRadius = 3 88 | //shapeLayer.borderColor = UIColor.grayColor() .CGColor 89 | shapeLayer.shadowPath = pat.cgPath 90 | shapeLayer.shouldRasterize = true 91 | baseView.layer.addSublayer(shapeLayer) //insertSublayer(shapeLayer, atIndex: 0) 92 | 93 | print(discription) 94 | 95 | let lblTitle = self.getLabel(withTextColot: UIColor.white, withFont: font) 96 | lblTitle.text = discription 97 | lblTitle.textAlignment = .center 98 | lblTitle.numberOfLines = 0 99 | lblTitle.backgroundColor = popupArrowColor 100 | baseView.addSubview(lblTitle) 101 | 102 | 103 | baseView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-5-[lblTitle]-5-|", options: [], metrics: nil, views: ["lblTitle" : lblTitle])) 104 | baseView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[lblTitle]|", options: [], metrics: nil, views: ["lblTitle" : lblTitle])) 105 | } 106 | 107 | override func touchesBegan(_ touches: Set, with event: UIEvent?) { 108 | 109 | removePopView() 110 | } 111 | 112 | func showPopView(){ 113 | self.alpha = 0.0 114 | (UIApplication.shared.delegate as! AppDelegate).window?.addSubview(self) 115 | UIView .animateKeyframes(withDuration: 0.5, delay: 0, options: [], animations: { () -> Void in 116 | self.alpha = 1 117 | }) { (flag : Bool) -> Void in 118 | } 119 | } 120 | 121 | func removePopView() { 122 | 123 | UIView .animateKeyframes(withDuration: 0.5, delay: 0, options: [], animations: { () -> Void in 124 | self.alpha = 0.01 125 | }) { (flag : Bool) -> Void in 126 | if flag { 127 | self.removeFromSuperview() 128 | } 129 | } 130 | } 131 | 132 | //MARK: get label 133 | private func getLabel(withTextColot objClr:UIColor,withFont objFont:UIFont) -> UILabel 134 | { 135 | let objLbl = UILabel() 136 | objLbl.translatesAutoresizingMaskIntoConstraints = false 137 | objLbl.font = objFont 138 | objLbl.clipsToBounds = true 139 | objLbl.textColor = objClr 140 | objLbl.backgroundColor = UIColor.clear 141 | return objLbl 142 | } 143 | 144 | fileprivate func checkTouching(_ point : CGPoint)->Bool { 145 | if point.x > baseView.frame.origin.x + baseView.frame.size.width || point.x < baseView.frame.origin.x { 146 | return true 147 | } 148 | else if point.y > baseView.frame.origin.y + baseView.frame.size.height || point.y < baseView.frame.origin.y { 149 | return true 150 | } 151 | return false 152 | } 153 | 154 | func addConstraintFunction(_ firstItem : AnyObject,FirstItemAttribure fAttribute:NSLayoutAttribute,relationIs relation:NSLayoutRelation,secondItem secondV:AnyObject?,SecondItemAttribure sAttribute:NSLayoutAttribute,multiplayer mu:CGFloat,constraint co:CGFloat,identifire strId:String?,addIn viewR:UIView)->Void { 155 | let horizontalConstraint = NSLayoutConstraint(item: firstItem, attribute:fAttribute, relatedBy: relation, toItem: secondV, attribute: sAttribute, multiplier: mu, constant: co) 156 | if strId != nil{ 157 | horizontalConstraint.identifier = strId 158 | } 159 | viewR.addConstraint(horizontalConstraint) 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Required/ImagePicker/ImagePickerVC.swift: -------------------------------------------------------------------------------- 1 | 2 | import UIKit 3 | import MobileCoreServices 4 | import PhotosUI 5 | import AVKit 6 | import AVFoundation 7 | 8 | /* 9 | How to use image picker vc class 10 | func presentVC(CompletionBlock:@escaping (_ result: AnyObject) -> Void) { 11 | let vc = ImagePickerVC() 12 | vc.completionBlock = CompletionBlock 13 | vc.isEditingAllowed = true 14 | vc.isImageProcessing = true 15 | self.present(vc, animated: true, completion: nil) 16 | } 17 | 18 | 19 | self.presentVC { (result) in 20 | if let Img = result as? UIImage{ 21 | print("Image is captured") 22 | } 23 | if let video = result as? String{ 24 | print("Image is stored") 25 | } 26 | } 27 | 28 | */ 29 | 30 | let APPDELEGATE = (UIApplication.shared.delegate as! AppDelegate) 31 | 32 | 33 | typealias CompletionBlock = (_ result: AnyObject) -> Void 34 | typealias ImageimgPicker = (_ image:AnyObject?) -> Void 35 | 36 | 37 | class ImagePickerVC: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate { 38 | 39 | 40 | //MARK: 41 | //MARK: Variables 42 | 43 | var completionBlock : CompletionBlock? 44 | var isEditingAllowed : Bool? 45 | var isImageProcessing : Bool? 46 | 47 | fileprivate let maxResolution = CGSize(width: 3000, height: 3000) 48 | fileprivate let resetImageSize = CGFloat(1000.0) 49 | fileprivate var imgPicker: ImageimgPicker? 50 | fileprivate let videoCaption = "TestVideo" 51 | 52 | 53 | //MARK: 54 | //MARK:UI 55 | 56 | override func viewDidLoad() { 57 | super.viewDidLoad() 58 | 59 | defaultInit() 60 | 61 | // Do any additional setup after loading the view. 62 | } 63 | 64 | 65 | 66 | override func didReceiveMemoryWarning() { 67 | super.didReceiveMemoryWarning() 68 | // Dispose of any resources that can be recreated. 69 | } 70 | 71 | 72 | fileprivate func defaultInit(){ 73 | self.showImagePickerOption(self.view) { (obj) in 74 | 75 | if (obj != nil){ 76 | self.completionBlock!(obj!) 77 | } 78 | 79 | self.dismiss(animated: true, completion:nil) 80 | } 81 | } 82 | 83 | //MARK:- Show Image Optionals 84 | fileprivate func showImagePickerOption(_ sourceView:UIView,completionHandler handler:ImageimgPicker?) { 85 | 86 | let galleryAction = UIAlertAction(title:"Gallery", style: UIAlertActionStyle.default, handler: { (UIAlertAction) -> Void in 87 | self.checkPermisssionForImage(UIImagePickerControllerSourceType.photoLibrary,PermissionProvided: { (result) in 88 | if(result){ 89 | self.showCameraOrGallery(UIImagePickerControllerSourceType.photoLibrary) 90 | } 91 | }) 92 | }) 93 | 94 | let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: { (UIAlertAction) -> Void in 95 | self.dismiss(animated: true, completion: nil) 96 | }) 97 | 98 | let alerActionSheet = UIAlertController(title:"Profile Imag", message:"please select option", preferredStyle: UIAlertControllerStyle.actionSheet) 99 | 100 | if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){ 101 | let cameraAction = UIAlertAction(title: "Camera", style: UIAlertActionStyle.default, handler: { (UIAlertAction) -> Void in 102 | self.checkPermisssionForImage(UIImagePickerControllerSourceType.camera,PermissionProvided:{(result) in 103 | if(result){ 104 | self.showCameraOrGallery(UIImagePickerControllerSourceType.camera) 105 | } 106 | }) 107 | }) 108 | alerActionSheet.addAction(cameraAction) 109 | } 110 | 111 | alerActionSheet.addAction(galleryAction) 112 | alerActionSheet.addAction(cancelAction) 113 | alerActionSheet.popoverPresentationController?.sourceView = sourceView 114 | alerActionSheet.popoverPresentationController?.sourceRect = CGRect(x: sourceView.bounds.width / 2.0, y: sourceView.bounds.height / 2.0, width: 1.0, height: 1.0) 115 | APPDELEGATE.window?.rootViewController?.present(alerActionSheet, animated: true, completion: nil) 116 | imgPicker = handler 117 | } 118 | fileprivate func showCameraOrGallery(_ source:UIImagePickerControllerSourceType) { 119 | let imag = UIImagePickerController() 120 | imag.delegate = self 121 | imag.sourceType = source; 122 | imag.mediaTypes = (isImageProcessing == true ? [kUTTypeImage as String] : [kUTTypeMovie as String]) 123 | imag.allowsEditing = isEditingAllowed! 124 | APPDELEGATE.window?.rootViewController?.present(imag, animated: true, completion: nil) 125 | } 126 | 127 | //MARK:- Image Picker Delegate Method 128 | 129 | func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 130 | picker.dismiss(animated: true, completion: nil) 131 | 132 | if (isImageProcessing)!{ 133 | let success = validateImage(info: info).0 134 | let img = validateImage(info: info).1 135 | 136 | if let handler = imgPicker { 137 | handler(img) 138 | } 139 | if(!success) 140 | { 141 | print("validation failed") 142 | } 143 | }else{ 144 | 145 | let success = validateVideo(info: info).0 146 | let videoData = validateVideo(info: info).1 147 | 148 | if let handler = imgPicker { 149 | handler(videoData as AnyObject?) 150 | } 151 | if(!success) 152 | { 153 | print("validation failed") 154 | } 155 | } 156 | 157 | 158 | self.dismiss(animated: true, completion: nil) 159 | 160 | imgPicker = nil 161 | } 162 | 163 | func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { 164 | picker.dismiss(animated: true, completion: nil) 165 | if let handler = imgPicker { 166 | handler(nil) 167 | } 168 | imgPicker = nil 169 | } 170 | 171 | //MARK:- Check Permission Method 172 | 173 | fileprivate func checkPermisssionForImage(_ sourceType:UIImagePickerControllerSourceType,PermissionProvided:@escaping (_ result: Bool) -> Void) { 174 | if(sourceType == .camera){ 175 | AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted:Bool) in 176 | if(granted){ 177 | 178 | DispatchQueue.main.async(execute: { 179 | PermissionProvided(true) 180 | }) 181 | } else { 182 | let permissionAlert = UIAlertController(title: "Permission", message: "App don't have a permission to access the Camera please go to the setting give the permission.", preferredStyle: .alert) 183 | let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) 184 | let settingAction = UIAlertAction(title: "Setting", style: .default, handler: { (UIAlertAction) -> Void in 185 | 186 | let url = URL(string:UIApplicationOpenSettingsURLString)! 187 | if #available(iOS 10.0, *) { 188 | UIApplication.shared.open(url, options: [:], completionHandler: nil) 189 | } else { 190 | UIApplication.shared.openURL(url) 191 | } 192 | 193 | }) 194 | 195 | permissionAlert.addAction(okAction) 196 | permissionAlert.addAction(settingAction) 197 | 198 | DispatchQueue.main.async(execute: { 199 | APPDELEGATE.window?.rootViewController!.present(permissionAlert, animated: true, completion: nil) 200 | PermissionProvided(false) 201 | }) 202 | } 203 | }) 204 | 205 | } else { 206 | 207 | PHPhotoLibrary.requestAuthorization({(status:PHAuthorizationStatus)in 208 | switch status 209 | { 210 | case .notDetermined , .authorized : 211 | DispatchQueue.main.async(execute: { 212 | PermissionProvided(true) 213 | }) 214 | break 215 | 216 | case .denied , .restricted: 217 | let permissionAlert = UIAlertController(title: "Permission", message: "App don't have a permission to access the photos please go to the setting give the permission.", preferredStyle: .alert) 218 | let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) 219 | let settingAction = UIAlertAction(title: "Setting", style: .default, handler: { (UIAlertAction) -> Void in 220 | 221 | 222 | let url = URL(string:UIApplicationOpenSettingsURLString)! 223 | if #available(iOS 10.0, *) { 224 | UIApplication.shared.open(url, options: [:], completionHandler: nil) 225 | } else { 226 | UIApplication.shared.openURL(url) 227 | } 228 | 229 | }) 230 | 231 | permissionAlert.addAction(okAction) 232 | permissionAlert.addAction(settingAction) 233 | DispatchQueue.main.async(execute: { 234 | APPDELEGATE.window?.rootViewController!.present(permissionAlert, animated: true, completion: nil) 235 | PermissionProvided(false) 236 | }) 237 | break 238 | } 239 | }) 240 | } 241 | } 242 | 243 | //MARK:- Validate Image 244 | fileprivate func validateImage(info : [String : Any])->(Bool,UIImage?){ 245 | 246 | var image : UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage 247 | 248 | //Resolution will be Priorotise first 249 | if (image.size.width) > maxResolution.width || (image.size.height) > maxResolution.height //Max Resolution 250 | { 251 | image = image.generateLowResolutionImage(maxLowResolutionSideLength: resetImageSize) 252 | return (true,image) 253 | } 254 | 255 | if (isEditingAllowed == true){//Edited Image 256 | if let img = info[UIImagePickerControllerEditedImage] as? UIImage 257 | { 258 | image = img 259 | return (true,img) 260 | } 261 | } 262 | 263 | //Original Image 264 | if let img = info[UIImagePickerControllerOriginalImage] as? UIImage 265 | { 266 | return (true,img) 267 | } 268 | 269 | return (false,nil) 270 | 271 | } 272 | //MARK:- Validate Image 273 | fileprivate func validateVideo(info : [String : Any])->(Bool,String?){ 274 | 275 | let vedioUrl = info[UIImagePickerControllerMediaURL] as? URL 276 | let asset = AVAsset(url: vedioUrl!) 277 | let currentVideoDuration : CMTime = asset.duration 278 | 279 | let durationInSeconds: Double = CMTimeGetSeconds(currentVideoDuration) 280 | let minutes: Double = floor(durationInSeconds / 60) 281 | 282 | if (minutes > 1)//If greated than 1 Min 283 | { 284 | return (false,nil) 285 | }else{ 286 | let myVideoVarData = try! Data(contentsOf: vedioUrl!) 287 | 288 | let tempPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true) 289 | let tempDocumentsDirectory: AnyObject = tempPath[0] as AnyObject 290 | let tempDataPath = tempDocumentsDirectory.appendingPathComponent(String(format:"%@.mov",videoCaption)) as String 291 | try? myVideoVarData.write(to: URL(fileURLWithPath: tempDataPath), options: []) 292 | return (true,getDefaultVedioPath()) 293 | } 294 | 295 | 296 | } 297 | 298 | func getDefaultVedioPath()->String{ 299 | return String(format:"%@/%@.mov",getDocumentDir(),videoCaption); 300 | } 301 | 302 | //MARK:Common Video 303 | fileprivate func getDocumentDir()->String{ 304 | let tempPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true) 305 | let tempDocumentsDirectory: AnyObject = tempPath[0] as AnyObject 306 | return (tempDocumentsDirectory as? String)! 307 | 308 | } 309 | deinit{ 310 | print("Deallocated ImagePickerVC") 311 | } 312 | } 313 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Libs/DLCategory+Extention.swift: -------------------------------------------------------------------------------- 1 | 2 | 3 | import Foundation 4 | import UIKit 5 | 6 | 7 | 8 | struct Name { 9 | 10 | let lblName:UILabel? = nil 11 | let txtName:UITextField? = nil 12 | /* TextView and TextField both 95% property same so we can use it 'txt */ 13 | let txtVwName:UITextView? = nil 14 | let tblDoctor:UITableView? = nil 15 | let clnDoctor:UICollectionView? = nil 16 | /* for view we can use objectname first than view objectname always Start with 'small' and view always 'capital' */ 17 | let subView:UIView? = nil 18 | let popupView:UIView? = nil 19 | let calenderView:UIView? = nil 20 | 21 | let scrollCalender:UIScrollView? = nil 22 | /* scrollview use 'Controller' name batter than name Main */ 23 | let scrollMain:UIScrollView? = nil 24 | let scrollHospital:UIScrollView? = nil 25 | 26 | 27 | let segmentDepartment:UISegmentedControl? = nil 28 | let progressClock:UIProgressView? = nil 29 | 30 | //Sid 31 | let strName:String = "" 32 | let intCounter:Int = 0 33 | let int8Counter:Int8 = 0 34 | let intCtr:NSInteger = 0 35 | let fltPercentage:Float = 1.0 36 | let fltWidth:CGFloat=0.0 37 | let dblLocation:Double = 1.0 38 | 39 | let arrList:NSMutableArray 40 | let arrData:NSArray 41 | let dicData:NSDictionary 42 | let objModelClass:Any 43 | let fontHelvetica:UIFont 44 | let clrRed:UIColor 45 | } 46 | 47 | 48 | extension UIView{ 49 | 50 | 51 | 52 | 53 | 54 | @IBInspectable var DLCorneredius:CGFloat{ 55 | 56 | get{ 57 | return layer.cornerRadius 58 | } 59 | set{ 60 | self.layer.cornerRadius = newValue 61 | self.layer.masksToBounds = newValue > 0 62 | } 63 | } 64 | @IBInspectable var DLBorderWidth:CGFloat{ 65 | 66 | get{ 67 | return layer.borderWidth 68 | } 69 | set{ 70 | self.layer.borderWidth = newValue 71 | self.layer.masksToBounds = newValue > 0 72 | } 73 | } 74 | 75 | @IBInspectable var DLBorderColor:UIColor{ 76 | 77 | get{ 78 | return self.DLBorderColor 79 | } 80 | set{ 81 | self.layer.borderColor = newValue.cgColor 82 | 83 | } 84 | } 85 | @IBInspectable var DLRoundDynamic:Bool{ 86 | 87 | get{ 88 | return false 89 | } 90 | set{ 91 | if newValue == true { 92 | 93 | self.perform(#selector(UIView.afterDelay), with: nil, afterDelay: 0.1) 94 | } 95 | 96 | } 97 | 98 | } 99 | func afterDelay(){ 100 | 101 | let Height = self.frame.size.height 102 | self.layer.cornerRadius = Height/2; 103 | self.layer.masksToBounds = true; 104 | 105 | 106 | } 107 | @IBInspectable var DLRound:Bool{ 108 | get{ 109 | return false 110 | } 111 | set{ 112 | if newValue == true { 113 | self.layer.cornerRadius = self.frame.size.height/2; 114 | self.layer.masksToBounds = true; 115 | } 116 | 117 | } 118 | } 119 | @IBInspectable var DLShadow:Bool{ 120 | get{ 121 | return false 122 | } 123 | set{ 124 | if newValue == true { 125 | self.layer.masksToBounds = false 126 | self.layer.shadowColor = UIColor.black.cgColor 127 | self.layer.shadowOffset = CGSize(width: 1.0, height: 1.0) 128 | self.layer.shadowOpacity = 0.6; 129 | 130 | } 131 | 132 | } 133 | 134 | } 135 | @IBInspectable var DLclipsToBounds:Bool{ 136 | get{ 137 | return false 138 | } 139 | set{ 140 | if newValue == true { 141 | 142 | self.clipsToBounds = true; 143 | }else{ 144 | self.clipsToBounds = false 145 | } 146 | 147 | } 148 | 149 | } 150 | 151 | 152 | func shadowWith(alph:Float){ 153 | self.layer.masksToBounds = false 154 | self.layer.shadowColor = UIColor.black.cgColor 155 | self.layer.shadowOffset = CGSize(width: 1.0, height: 1.0) 156 | self.layer.shadowOpacity = alph 157 | } 158 | 159 | } 160 | 161 | extension UILabel{ 162 | 163 | @IBInspectable var FontAutomatic:Bool{ 164 | get{ 165 | return true 166 | } 167 | set{ 168 | 169 | if newValue == true { 170 | 171 | let height = (self.frame.size.height*ScreenSize.SCREEN_HEIGHT)/568; 172 | self.font = UIFont(name:self.font.fontName, size:(height*self.font.pointSize)/self.frame.size.height ) 173 | } 174 | 175 | } 176 | 177 | } 178 | 179 | 180 | 181 | } 182 | extension UITextView { 183 | 184 | @IBInspectable var FontAutomatic:Bool{ 185 | get{ 186 | return true 187 | } 188 | set{ 189 | 190 | if newValue == true { 191 | 192 | let height = (self.frame.size.height*ScreenSize.SCREEN_HEIGHT)/568; 193 | self.font = UIFont(name:self.font!.fontName, size:(height*self.font!.pointSize)/self.frame.size.height ) 194 | } 195 | 196 | } 197 | 198 | } 199 | 200 | 201 | 202 | 203 | @IBInspectable var Pedding:Bool{ 204 | get{ 205 | return true 206 | } 207 | set{ 208 | 209 | if newValue == true { 210 | 211 | let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 8, height: self.frame.height)) 212 | self.addSubview(paddingView) 213 | } 214 | 215 | } 216 | 217 | } 218 | 219 | 220 | 221 | } 222 | extension UITextField{ 223 | 224 | @IBInspectable var FontAutomatic:Bool{ 225 | get{ 226 | return true 227 | } 228 | set{ 229 | 230 | if newValue == true { 231 | 232 | let height = (self.frame.size.height*ScreenSize.SCREEN_HEIGHT)/568; 233 | self.font = UIFont(name:self.font!.fontName, size:(height*self.font!.pointSize)/self.frame.size.height ) 234 | } 235 | 236 | } 237 | 238 | } 239 | 240 | 241 | 242 | func setBottomBorder(_ color:UIColor, height:CGFloat) { 243 | 244 | var view = self.viewWithTag(2525) 245 | if view == nil { 246 | 247 | view = UIView(frame:CGRect(x: 0, y: self.frame.size.height - height, width: self.frame.size.width, height: 1)) 248 | view?.backgroundColor = color 249 | view?.tag = 2525 250 | self .addSubview(view!) 251 | } 252 | 253 | 254 | } 255 | 256 | 257 | @IBInspectable var Pedding:Bool{ 258 | get{ 259 | return true 260 | } 261 | set{ 262 | 263 | if newValue == true { 264 | 265 | let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 8, height: self.frame.height)) 266 | self.leftView = paddingView 267 | self.leftViewMode = UITextFieldViewMode.always } 268 | 269 | } 270 | 271 | } 272 | 273 | 274 | func leftButton(image:UIImage?) { 275 | 276 | let btn = UIButton.init(type: .custom) 277 | btn.setImage(image, for: .normal) 278 | btn.frame = CGRect.init(x: 0, y: 0, width: self.frame.size.height, height: self.frame.size.height) 279 | self.leftView = btn; 280 | self.leftViewMode = .always 281 | // return btn 282 | 283 | } 284 | 285 | func rightButton(imageName:String) { 286 | 287 | let btn = UIButton.init(type: .custom) 288 | btn.setImage(UIImage.init(named: imageName), for: .normal) 289 | btn.frame = CGRect.init(x: (ScreenSize.SCREEN_WIDTH - self.frame.size.height), y: 0, width: self.frame.size.height, height: self.frame.size.height) 290 | self.rightView = btn; 291 | self.rightViewMode = .always 292 | // return btn 293 | 294 | } 295 | 296 | 297 | 298 | } 299 | extension UIButton{ 300 | 301 | @IBInspectable var FontAutomatic:Bool{ 302 | get{ 303 | return true 304 | } 305 | set{ 306 | 307 | if newValue == true { 308 | 309 | let height = (self.frame.size.height*ScreenSize.SCREEN_HEIGHT)/568; 310 | self.titleLabel!.font = UIFont(name:self.titleLabel!.font!.fontName, size:(height*self.titleLabel!.font!.pointSize)/self.frame.size.height )! 311 | } 312 | 313 | } 314 | 315 | } 316 | 317 | 318 | 319 | } 320 | extension String{ 321 | 322 | func isValidEmail() -> Bool { 323 | // print("validate calendar: \(testStr)") 324 | let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}" 325 | let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx) 326 | return emailTest.evaluate(with: self) 327 | } 328 | func isValidName() -> Bool { 329 | 330 | if characters.count > 0 { 331 | return true 332 | } 333 | return false 334 | 335 | 336 | } 337 | func isValidPassWord() -> Bool { 338 | 339 | if characters.count > 4 { 340 | return true 341 | } 342 | return false 343 | 344 | } 345 | func isValidFullname() -> Bool { 346 | 347 | let emailRegEx = "^[A-Za-z]+(?:\\s[A-Za-z]+)" 348 | let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx) 349 | return emailTest.evaluate(with: self) 350 | 351 | } 352 | func isValidZipcode() -> Bool { 353 | 354 | if characters.count == 5 || characters.count == 6 { 355 | return true 356 | } 357 | return false 358 | 359 | } 360 | 361 | func isValidMobile() -> Bool { 362 | 363 | 364 | if characters.count == 10 { 365 | return true 366 | } 367 | return false 368 | 369 | } 370 | 371 | func isEmptyText() -> Bool { 372 | 373 | let string = self.trimmingCharacters(in: NSCharacterSet.whitespaces) 374 | return string.isEmpty 375 | } 376 | 377 | 378 | } 379 | extension UIScrollView{ 380 | 381 | func AumaticScroller() { 382 | 383 | var contentRect = CGRect.zero 384 | for view in self.subviews{ 385 | contentRect = contentRect.union(view.frame); 386 | } 387 | 388 | self.contentSize = contentRect.size; 389 | } 390 | func AumaticScrollerFaxible() { 391 | 392 | var contentRect = CGRect.zero 393 | for view in self.subviews{ 394 | contentRect = contentRect.union(view.frame); 395 | } 396 | 397 | self.contentSize = CGSize(width: contentRect.width, height: contentRect.height + 60) 398 | } 399 | 400 | 401 | } 402 | extension UIImage{ 403 | 404 | func DLresizeImage(_ newWidth: CGFloat) -> UIImage { 405 | 406 | let scale = newWidth / self.size.width 407 | let newHeight = self.size.height * scale 408 | UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight)) 409 | self.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight)) 410 | let newImage = UIGraphicsGetImageFromCurrentImageContext() 411 | UIGraphicsEndImageContext() 412 | return newImage! 413 | } 414 | 415 | 416 | 417 | } 418 | extension UIViewController { 419 | 420 | func showNavigationBar(){ 421 | 422 | self.navigationController?.setNavigationBarHidden(false, animated: true) 423 | self.navigationController?.navigationBar.tintColor = UIColor.white 424 | self.navigationController?.navigationBar.barTintColor = #colorLiteral(red: 0.01938943379, green: 0.4767298698, blue: 0.2441024482, alpha: 1) 425 | // self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white,NSFontAttributeName:UIFont.app_reguler(withSize: FONTSIZE.regulerSize)] 426 | self.navigationController?.navigationBar.isTranslucent = false; 427 | self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true 428 | self.navigationController?.interactivePopGestureRecognizer?.delegate = nil 429 | 430 | 431 | 432 | 433 | } 434 | func showNavigationBarWithBack(){ 435 | 436 | self.navigationController?.setNavigationBarHidden(false, animated: true) 437 | self.navigationController?.navigationBar.tintColor = UIColor.white 438 | self.navigationController?.navigationBar.barTintColor = #colorLiteral(red: 0.01938943379, green: 0.4767298698, blue: 0.2441024482, alpha: 1) 439 | // self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white,NSFontAttributeName:UIFont.app_reguler(withSize: FONTSIZE.regulerSize)] 440 | self.navigationController?.navigationBar.isTranslucent = false; 441 | self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true 442 | self.navigationController?.interactivePopGestureRecognizer?.delegate = nil 443 | 444 | 445 | let backItem = UIBarButtonItem.init(image:#imageLiteral(resourceName: "back"), style: .plain, target: self, action: #selector(UIViewController.backViewController)) 446 | backItem.tintColor = UIColor.white 447 | self.navigationItem.leftBarButtonItem = backItem 448 | 449 | 450 | 451 | } 452 | 453 | func leftBarItem(image:UIImage,name:String?) -> UIBarButtonItem { 454 | 455 | let leftItem = UIBarButtonItem.init(image: image, style: .plain, target: self, action: nil) 456 | leftItem.title = name 457 | leftItem.tintColor = UIColor.white 458 | self.navigationItem.leftBarButtonItem = leftItem 459 | return leftItem 460 | } 461 | func rightBarItem(image:UIImage?,name:String?) -> UIBarButtonItem { 462 | 463 | let rightItem = UIBarButtonItem.init(image: image, style: .plain, target: self, action: nil) 464 | rightItem.title = name 465 | rightItem.tintColor = UIColor.white 466 | self.navigationItem.rightBarButtonItem = rightItem 467 | return rightItem 468 | } 469 | 470 | func getBarButtonItem(image:UIImage?,name:String?) -> UIBarButtonItem { 471 | 472 | let rightItem = UIBarButtonItem.init(image: image, style: .plain, target: self, action: nil) 473 | rightItem.title = name 474 | rightItem.tintColor = UIColor.white 475 | return rightItem 476 | 477 | } 478 | 479 | func backViewController() { 480 | 481 | self.navigationController!.popViewController(animated: true) 482 | } 483 | 484 | 485 | } 486 | -------------------------------------------------------------------------------- /ShortCode/ShortCode.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0237FA801EF547B800AFBB8F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FA7F1EF547B800AFBB8F /* AppDelegate.swift */; }; 11 | 0237FA821EF547B800AFBB8F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FA811EF547B800AFBB8F /* ViewController.swift */; }; 12 | 0237FA851EF547B800AFBB8F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0237FA831EF547B800AFBB8F /* Main.storyboard */; }; 13 | 0237FA871EF547B800AFBB8F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0237FA861EF547B800AFBB8F /* Assets.xcassets */; }; 14 | 0237FA8A1EF547B800AFBB8F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0237FA881EF547B800AFBB8F /* LaunchScreen.storyboard */; }; 15 | 0237FA9E1EF547C700AFBB8F /* UserClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FA921EF547C700AFBB8F /* UserClass.swift */; }; 16 | 0237FA9F1EF547C700AFBB8F /* AllConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FA941EF547C700AFBB8F /* AllConstants.swift */; }; 17 | 0237FAA01EF547C700AFBB8F /* UIImageExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FA961EF547C700AFBB8F /* UIImageExtension.swift */; }; 18 | 0237FAA11EF547C700AFBB8F /* ImagePickerVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FA9B1EF547C700AFBB8F /* ImagePickerVC.swift */; }; 19 | 0237FAA21EF547C700AFBB8F /* QueueManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FA9D1EF547C700AFBB8F /* QueueManager.swift */; }; 20 | 0237FAAC1EF54A0700AFBB8F /* CustomImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FAA51EF54A0700AFBB8F /* CustomImageView.swift */; }; 21 | 0237FAAD1EF54A0700AFBB8F /* DateValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FAA61EF54A0700AFBB8F /* DateValidator.swift */; }; 22 | 0237FAAE1EF54A0700AFBB8F /* DLCategory+Extention.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FAA71EF54A0700AFBB8F /* DLCategory+Extention.swift */; }; 23 | 0237FAB11EF54A0700AFBB8F /* ShowDescriptionPopup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FAAA1EF54A0700AFBB8F /* ShowDescriptionPopup.swift */; }; 24 | 0237FAB21EF54A0700AFBB8F /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0237FAAB1EF54A0700AFBB8F /* Theme.swift */; }; 25 | /* End PBXBuildFile section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | 0237FA7C1EF547B800AFBB8F /* ShortCode.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShortCode.app; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | 0237FA7F1EF547B800AFBB8F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 30 | 0237FA811EF547B800AFBB8F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 31 | 0237FA841EF547B800AFBB8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 32 | 0237FA861EF547B800AFBB8F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 33 | 0237FA891EF547B800AFBB8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 34 | 0237FA8B1EF547B800AFBB8F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 0237FA921EF547C700AFBB8F /* UserClass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserClass.swift; sourceTree = ""; }; 36 | 0237FA941EF547C700AFBB8F /* AllConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AllConstants.swift; sourceTree = ""; }; 37 | 0237FA961EF547C700AFBB8F /* UIImageExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageExtension.swift; sourceTree = ""; }; 38 | 0237FA9B1EF547C700AFBB8F /* ImagePickerVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImagePickerVC.swift; sourceTree = ""; }; 39 | 0237FA9D1EF547C700AFBB8F /* QueueManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueueManager.swift; sourceTree = ""; }; 40 | 0237FAA51EF54A0700AFBB8F /* CustomImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomImageView.swift; sourceTree = ""; }; 41 | 0237FAA61EF54A0700AFBB8F /* DateValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateValidator.swift; sourceTree = ""; }; 42 | 0237FAA71EF54A0700AFBB8F /* DLCategory+Extention.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DLCategory+Extention.swift"; sourceTree = ""; }; 43 | 0237FAAA1EF54A0700AFBB8F /* ShowDescriptionPopup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowDescriptionPopup.swift; sourceTree = ""; }; 44 | 0237FAAB1EF54A0700AFBB8F /* Theme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = ""; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 0237FA791EF547B800AFBB8F /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | ); 53 | runOnlyForDeploymentPostprocessing = 0; 54 | }; 55 | /* End PBXFrameworksBuildPhase section */ 56 | 57 | /* Begin PBXGroup section */ 58 | 0237FA731EF547B800AFBB8F = { 59 | isa = PBXGroup; 60 | children = ( 61 | 0237FA7E1EF547B800AFBB8F /* ShortCode */, 62 | 0237FA7D1EF547B800AFBB8F /* Products */, 63 | ); 64 | sourceTree = ""; 65 | }; 66 | 0237FA7D1EF547B800AFBB8F /* Products */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 0237FA7C1EF547B800AFBB8F /* ShortCode.app */, 70 | ); 71 | name = Products; 72 | sourceTree = ""; 73 | }; 74 | 0237FA7E1EF547B800AFBB8F /* ShortCode */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 0237FAA31EF54A0700AFBB8F /* Libs */, 78 | 0237FA911EF547C700AFBB8F /* Model */, 79 | 0237FA931EF547C700AFBB8F /* Required */, 80 | 0237FA7F1EF547B800AFBB8F /* AppDelegate.swift */, 81 | 0237FA811EF547B800AFBB8F /* ViewController.swift */, 82 | 0237FA831EF547B800AFBB8F /* Main.storyboard */, 83 | 0237FA861EF547B800AFBB8F /* Assets.xcassets */, 84 | 0237FA881EF547B800AFBB8F /* LaunchScreen.storyboard */, 85 | 0237FA8B1EF547B800AFBB8F /* Info.plist */, 86 | ); 87 | path = ShortCode; 88 | sourceTree = ""; 89 | }; 90 | 0237FA911EF547C700AFBB8F /* Model */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 0237FA921EF547C700AFBB8F /* UserClass.swift */, 94 | ); 95 | path = Model; 96 | sourceTree = ""; 97 | }; 98 | 0237FA931EF547C700AFBB8F /* Required */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 0237FA941EF547C700AFBB8F /* AllConstants.swift */, 102 | 0237FA951EF547C700AFBB8F /* AppExtension */, 103 | 0237FA9A1EF547C700AFBB8F /* ImagePicker */, 104 | 0237FA9C1EF547C700AFBB8F /* QueueManager */, 105 | ); 106 | path = Required; 107 | sourceTree = ""; 108 | }; 109 | 0237FA951EF547C700AFBB8F /* AppExtension */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 0237FA961EF547C700AFBB8F /* UIImageExtension.swift */, 113 | ); 114 | path = "AppExtension "; 115 | sourceTree = ""; 116 | }; 117 | 0237FA9A1EF547C700AFBB8F /* ImagePicker */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | 0237FA9B1EF547C700AFBB8F /* ImagePickerVC.swift */, 121 | ); 122 | path = ImagePicker; 123 | sourceTree = ""; 124 | }; 125 | 0237FA9C1EF547C700AFBB8F /* QueueManager */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 0237FA9D1EF547C700AFBB8F /* QueueManager.swift */, 129 | ); 130 | path = QueueManager; 131 | sourceTree = ""; 132 | }; 133 | 0237FAA31EF54A0700AFBB8F /* Libs */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 0237FAA41EF54A0700AFBB8F /* CustomImageView */, 137 | 0237FAA61EF54A0700AFBB8F /* DateValidator.swift */, 138 | 0237FAA71EF54A0700AFBB8F /* DLCategory+Extention.swift */, 139 | 0237FAAA1EF54A0700AFBB8F /* ShowDescriptionPopup.swift */, 140 | 0237FAAB1EF54A0700AFBB8F /* Theme.swift */, 141 | ); 142 | path = Libs; 143 | sourceTree = ""; 144 | }; 145 | 0237FAA41EF54A0700AFBB8F /* CustomImageView */ = { 146 | isa = PBXGroup; 147 | children = ( 148 | 0237FAA51EF54A0700AFBB8F /* CustomImageView.swift */, 149 | ); 150 | path = CustomImageView; 151 | sourceTree = ""; 152 | }; 153 | /* End PBXGroup section */ 154 | 155 | /* Begin PBXNativeTarget section */ 156 | 0237FA7B1EF547B800AFBB8F /* ShortCode */ = { 157 | isa = PBXNativeTarget; 158 | buildConfigurationList = 0237FA8E1EF547B800AFBB8F /* Build configuration list for PBXNativeTarget "ShortCode" */; 159 | buildPhases = ( 160 | 0237FA781EF547B800AFBB8F /* Sources */, 161 | 0237FA791EF547B800AFBB8F /* Frameworks */, 162 | 0237FA7A1EF547B800AFBB8F /* Resources */, 163 | ); 164 | buildRules = ( 165 | ); 166 | dependencies = ( 167 | ); 168 | name = ShortCode; 169 | productName = ShortCode; 170 | productReference = 0237FA7C1EF547B800AFBB8F /* ShortCode.app */; 171 | productType = "com.apple.product-type.application"; 172 | }; 173 | /* End PBXNativeTarget section */ 174 | 175 | /* Begin PBXProject section */ 176 | 0237FA741EF547B800AFBB8F /* Project object */ = { 177 | isa = PBXProject; 178 | attributes = { 179 | LastSwiftUpdateCheck = 0830; 180 | LastUpgradeCheck = 0830; 181 | ORGANIZATIONNAME = Pulkeet; 182 | TargetAttributes = { 183 | 0237FA7B1EF547B800AFBB8F = { 184 | CreatedOnToolsVersion = 8.3.1; 185 | ProvisioningStyle = Automatic; 186 | }; 187 | }; 188 | }; 189 | buildConfigurationList = 0237FA771EF547B800AFBB8F /* Build configuration list for PBXProject "ShortCode" */; 190 | compatibilityVersion = "Xcode 3.2"; 191 | developmentRegion = English; 192 | hasScannedForEncodings = 0; 193 | knownRegions = ( 194 | en, 195 | Base, 196 | ); 197 | mainGroup = 0237FA731EF547B800AFBB8F; 198 | productRefGroup = 0237FA7D1EF547B800AFBB8F /* Products */; 199 | projectDirPath = ""; 200 | projectRoot = ""; 201 | targets = ( 202 | 0237FA7B1EF547B800AFBB8F /* ShortCode */, 203 | ); 204 | }; 205 | /* End PBXProject section */ 206 | 207 | /* Begin PBXResourcesBuildPhase section */ 208 | 0237FA7A1EF547B800AFBB8F /* Resources */ = { 209 | isa = PBXResourcesBuildPhase; 210 | buildActionMask = 2147483647; 211 | files = ( 212 | 0237FA8A1EF547B800AFBB8F /* LaunchScreen.storyboard in Resources */, 213 | 0237FA871EF547B800AFBB8F /* Assets.xcassets in Resources */, 214 | 0237FA851EF547B800AFBB8F /* Main.storyboard in Resources */, 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | }; 218 | /* End PBXResourcesBuildPhase section */ 219 | 220 | /* Begin PBXSourcesBuildPhase section */ 221 | 0237FA781EF547B800AFBB8F /* Sources */ = { 222 | isa = PBXSourcesBuildPhase; 223 | buildActionMask = 2147483647; 224 | files = ( 225 | 0237FAAE1EF54A0700AFBB8F /* DLCategory+Extention.swift in Sources */, 226 | 0237FAAD1EF54A0700AFBB8F /* DateValidator.swift in Sources */, 227 | 0237FA821EF547B800AFBB8F /* ViewController.swift in Sources */, 228 | 0237FAAC1EF54A0700AFBB8F /* CustomImageView.swift in Sources */, 229 | 0237FA801EF547B800AFBB8F /* AppDelegate.swift in Sources */, 230 | 0237FAA11EF547C700AFBB8F /* ImagePickerVC.swift in Sources */, 231 | 0237FAB11EF54A0700AFBB8F /* ShowDescriptionPopup.swift in Sources */, 232 | 0237FA9E1EF547C700AFBB8F /* UserClass.swift in Sources */, 233 | 0237FAA01EF547C700AFBB8F /* UIImageExtension.swift in Sources */, 234 | 0237FA9F1EF547C700AFBB8F /* AllConstants.swift in Sources */, 235 | 0237FAA21EF547C700AFBB8F /* QueueManager.swift in Sources */, 236 | 0237FAB21EF54A0700AFBB8F /* Theme.swift in Sources */, 237 | ); 238 | runOnlyForDeploymentPostprocessing = 0; 239 | }; 240 | /* End PBXSourcesBuildPhase section */ 241 | 242 | /* Begin PBXVariantGroup section */ 243 | 0237FA831EF547B800AFBB8F /* Main.storyboard */ = { 244 | isa = PBXVariantGroup; 245 | children = ( 246 | 0237FA841EF547B800AFBB8F /* Base */, 247 | ); 248 | name = Main.storyboard; 249 | sourceTree = ""; 250 | }; 251 | 0237FA881EF547B800AFBB8F /* LaunchScreen.storyboard */ = { 252 | isa = PBXVariantGroup; 253 | children = ( 254 | 0237FA891EF547B800AFBB8F /* Base */, 255 | ); 256 | name = LaunchScreen.storyboard; 257 | sourceTree = ""; 258 | }; 259 | /* End PBXVariantGroup section */ 260 | 261 | /* Begin XCBuildConfiguration section */ 262 | 0237FA8C1EF547B800AFBB8F /* Debug */ = { 263 | isa = XCBuildConfiguration; 264 | buildSettings = { 265 | ALWAYS_SEARCH_USER_PATHS = NO; 266 | CLANG_ANALYZER_NONNULL = YES; 267 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 268 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 269 | CLANG_CXX_LIBRARY = "libc++"; 270 | CLANG_ENABLE_MODULES = YES; 271 | CLANG_ENABLE_OBJC_ARC = YES; 272 | CLANG_WARN_BOOL_CONVERSION = YES; 273 | CLANG_WARN_CONSTANT_CONVERSION = YES; 274 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 275 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 276 | CLANG_WARN_EMPTY_BODY = YES; 277 | CLANG_WARN_ENUM_CONVERSION = YES; 278 | CLANG_WARN_INFINITE_RECURSION = YES; 279 | CLANG_WARN_INT_CONVERSION = YES; 280 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 281 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 282 | CLANG_WARN_UNREACHABLE_CODE = YES; 283 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 284 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 285 | COPY_PHASE_STRIP = NO; 286 | DEBUG_INFORMATION_FORMAT = dwarf; 287 | ENABLE_STRICT_OBJC_MSGSEND = YES; 288 | ENABLE_TESTABILITY = YES; 289 | GCC_C_LANGUAGE_STANDARD = gnu99; 290 | GCC_DYNAMIC_NO_PIC = NO; 291 | GCC_NO_COMMON_BLOCKS = YES; 292 | GCC_OPTIMIZATION_LEVEL = 0; 293 | GCC_PREPROCESSOR_DEFINITIONS = ( 294 | "DEBUG=1", 295 | "$(inherited)", 296 | ); 297 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 298 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 299 | GCC_WARN_UNDECLARED_SELECTOR = YES; 300 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 301 | GCC_WARN_UNUSED_FUNCTION = YES; 302 | GCC_WARN_UNUSED_VARIABLE = YES; 303 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 304 | MTL_ENABLE_DEBUG_INFO = YES; 305 | ONLY_ACTIVE_ARCH = YES; 306 | SDKROOT = iphoneos; 307 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 308 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 309 | TARGETED_DEVICE_FAMILY = "1,2"; 310 | }; 311 | name = Debug; 312 | }; 313 | 0237FA8D1EF547B800AFBB8F /* Release */ = { 314 | isa = XCBuildConfiguration; 315 | buildSettings = { 316 | ALWAYS_SEARCH_USER_PATHS = NO; 317 | CLANG_ANALYZER_NONNULL = YES; 318 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 319 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 320 | CLANG_CXX_LIBRARY = "libc++"; 321 | CLANG_ENABLE_MODULES = YES; 322 | CLANG_ENABLE_OBJC_ARC = YES; 323 | CLANG_WARN_BOOL_CONVERSION = YES; 324 | CLANG_WARN_CONSTANT_CONVERSION = YES; 325 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 326 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 327 | CLANG_WARN_EMPTY_BODY = YES; 328 | CLANG_WARN_ENUM_CONVERSION = YES; 329 | CLANG_WARN_INFINITE_RECURSION = YES; 330 | CLANG_WARN_INT_CONVERSION = YES; 331 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 332 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 333 | CLANG_WARN_UNREACHABLE_CODE = YES; 334 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 335 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 336 | COPY_PHASE_STRIP = NO; 337 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 338 | ENABLE_NS_ASSERTIONS = NO; 339 | ENABLE_STRICT_OBJC_MSGSEND = YES; 340 | GCC_C_LANGUAGE_STANDARD = gnu99; 341 | GCC_NO_COMMON_BLOCKS = YES; 342 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 343 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 344 | GCC_WARN_UNDECLARED_SELECTOR = YES; 345 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 346 | GCC_WARN_UNUSED_FUNCTION = YES; 347 | GCC_WARN_UNUSED_VARIABLE = YES; 348 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 349 | MTL_ENABLE_DEBUG_INFO = NO; 350 | SDKROOT = iphoneos; 351 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 352 | TARGETED_DEVICE_FAMILY = "1,2"; 353 | VALIDATE_PRODUCT = YES; 354 | }; 355 | name = Release; 356 | }; 357 | 0237FA8F1EF547B800AFBB8F /* Debug */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 361 | INFOPLIST_FILE = ShortCode/Info.plist; 362 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 363 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 364 | PRODUCT_BUNDLE_IDENTIFIER = com.something.something.ShortCode; 365 | PRODUCT_NAME = "$(TARGET_NAME)"; 366 | SWIFT_VERSION = 3.0; 367 | }; 368 | name = Debug; 369 | }; 370 | 0237FA901EF547B800AFBB8F /* Release */ = { 371 | isa = XCBuildConfiguration; 372 | buildSettings = { 373 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 374 | INFOPLIST_FILE = ShortCode/Info.plist; 375 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 376 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 377 | PRODUCT_BUNDLE_IDENTIFIER = com.something.something.ShortCode; 378 | PRODUCT_NAME = "$(TARGET_NAME)"; 379 | SWIFT_VERSION = 3.0; 380 | }; 381 | name = Release; 382 | }; 383 | /* End XCBuildConfiguration section */ 384 | 385 | /* Begin XCConfigurationList section */ 386 | 0237FA771EF547B800AFBB8F /* Build configuration list for PBXProject "ShortCode" */ = { 387 | isa = XCConfigurationList; 388 | buildConfigurations = ( 389 | 0237FA8C1EF547B800AFBB8F /* Debug */, 390 | 0237FA8D1EF547B800AFBB8F /* Release */, 391 | ); 392 | defaultConfigurationIsVisible = 0; 393 | defaultConfigurationName = Release; 394 | }; 395 | 0237FA8E1EF547B800AFBB8F /* Build configuration list for PBXNativeTarget "ShortCode" */ = { 396 | isa = XCConfigurationList; 397 | buildConfigurations = ( 398 | 0237FA8F1EF547B800AFBB8F /* Debug */, 399 | 0237FA901EF547B800AFBB8F /* Release */, 400 | ); 401 | defaultConfigurationIsVisible = 0; 402 | }; 403 | /* End XCConfigurationList section */ 404 | }; 405 | rootObject = 0237FA741EF547B800AFBB8F /* Project object */; 406 | } 407 | -------------------------------------------------------------------------------- /ShortCode/ShortCode/Libs/DateValidator.swift: -------------------------------------------------------------------------------- 1 | 2 | import UIKit 3 | let kMinute = 60 4 | let kHour = kMinute * 60 5 | let kDaySeconds = kHour * 24 6 | let kDayMinutes = kMinute * 24 7 | let kWeek = kDayMinutes * 7 8 | let kMonth = kDayMinutes * 31 9 | let kYear = kDayMinutes * 365 10 | class DateValidator: NSObject 11 | { 12 | 13 | class var sharedInstance:DateValidator 14 | { 15 | 16 | struct singleton_date 17 | { 18 | static let instance_new = DateValidator() 19 | } 20 | return singleton_date.instance_new 21 | 22 | } 23 | fileprivate func setDateFormat(_ dateFormatter : DateFormatter ,dateFormat : String = "dd/MM/yyyy") 24 | { 25 | dateFormatter.dateFormat = dateFormat 26 | } 27 | //MARK: STRING TO DATE && DATE TO STRING 28 | func stringFromDate(_ date:Date,strDateFormat : String)-> String 29 | { 30 | let dateFormatter = DateFormatter() 31 | self.setDateFormat(dateFormatter,dateFormat: strDateFormat) 32 | let strDate = dateFormatter.string(from: date) 33 | return strDate 34 | } 35 | func dateFromString(_ strDate:String,strDateFormat : String)-> Date? 36 | { 37 | let dateFormatter = DateFormatter() 38 | self.setDateFormat(dateFormatter,dateFormat: strDateFormat) 39 | let getNSDate = dateFormatter.date(from: strDate) 40 | if((getNSDate) != nil) 41 | { 42 | return getNSDate! 43 | }else 44 | { 45 | 46 | return nil 47 | } 48 | } 49 | 50 | //MARK:TIMESTAMP FROM  (NSDATE AND STRINGDATE) 51 | func timestampFromDate(_ date : Date)->Int 52 | { 53 | let interval = Int(date.timeIntervalSince1970) 54 | return interval 55 | } 56 | func timestampFromDateString(_ strDate : String,strDateFormat : String)->Int 57 | { 58 | 59 | let dateFormatter = DateFormatter() 60 | self.setDateFormat(dateFormatter,dateFormat: strDateFormat) 61 | let date_new = dateFormatter.date(from: strDate) 62 | let interval = Int(date_new!.timeIntervalSince1970) 63 | return interval 64 | } 65 | 66 | //MARK:(NSDATE AND STRINGDATE) FROM TIMESTAMP 67 | func dateFromTimestamp(_ timeInterval : Double)->Date //JM EDITED INT TO DOUBLE 68 | { 69 | let date = Date(timeIntervalSince1970: TimeInterval(timeInterval)) 70 | return date 71 | } 72 | func stringFromTimestamp(_ timeInterval : Double ,strDateFormat : String)->String //JM EDITED INT TO DOUBLE 73 | { 74 | let dateFormatter = DateFormatter() 75 | self.setDateFormat(dateFormatter,dateFormat: strDateFormat) 76 | let date = Date(timeIntervalSince1970: TimeInterval(timeInterval)) 77 | return dateFormatter.string(from: date) 78 | } 79 | 80 | //MARK:CONVERT TIMESTAMP INTO (LOCAL AND UTC) 81 | func convertLocaleToUTCTimeZone(_ date : Date)->Date 82 | { 83 | let dateFormatter = DateFormatter() 84 | self.setDateFormat(dateFormatter,dateFormat: "dd/MM/yyyy hh:mm:ss") 85 | dateFormatter.timeZone = TimeZone(abbreviation:"UTC")! 86 | let strDate = dateFormatter.string(from: date) 87 | return dateFormatter.date(from: strDate)! 88 | } 89 | func convertUTCToLocaleTimeZone(_ date : Date)->Date 90 | { 91 | let dateFormatter = DateFormatter() 92 | self.setDateFormat(dateFormatter,dateFormat: "dd/MM/yyyy hh:mm:ss") 93 | dateFormatter.timeZone = TimeZone.autoupdatingCurrent 94 | let strDate = dateFormatter.string(from: date) 95 | return dateFormatter.date(from: strDate)! 96 | } 97 | 98 | //MARK: DATE EXIST BETWEEN 2 DATES 99 | func isDateExist(StartDate startDate: Date, EndDate endDate: Date,selectedDate : Date) -> Bool 100 | { 101 | 102 | let isExist = startDate.compare(selectedDate) == selectedDate.compare(endDate) 103 | if(isExist == false) 104 | { 105 | 106 | if startDate.compare(selectedDate) == ComparisonResult.orderedSame || endDate.compare(selectedDate) == ComparisonResult.orderedSame 107 | { 108 | return true 109 | } 110 | } 111 | return isExist 112 | } 113 | func daysBetween(_ minDate : Date, maxDate :Date)->Int 114 | { 115 | let calendar: Calendar = Calendar.current 116 | let date1 = calendar.startOfDay(for: minDate) 117 | let date2 = calendar.startOfDay(for: maxDate) 118 | let components = (calendar as NSCalendar).components(.day, from: date1, to: date2, options: []) 119 | return components.day! + 1 120 | 121 | } 122 | 123 | func daysBetween(StartindDate minDate : Date,EndingDate maxDate :Date)->Int 124 | { 125 | let calendar: Calendar = Calendar.current 126 | let date1 = calendar.startOfDay(for: minDate) 127 | let date2 = calendar.startOfDay(for: maxDate) 128 | let components = (calendar as NSCalendar).components(.day, from: date1, to: date2, options: []) 129 | return components.day! 130 | 131 | } 132 | 133 | func getDates(_ startDate:Date, endDate:Date, strDateFormat : String) -> NSArray 134 | { 135 | let arrDates = NSMutableArray() 136 | 137 | let cal = Calendar.current 138 | var days = DateComponents() 139 | var dayCount = 0 140 | let dateFormatter = DateFormatter() 141 | self.setDateFormat(dateFormatter,dateFormat: strDateFormat) 142 | arrDates.add(dateFormatter.string(from: startDate)) 143 | arrDates.add(dateFormatter.string(from: endDate)) 144 | while true 145 | { 146 | days.day = dayCount 147 | let date:Date = (cal as NSCalendar).date(byAdding: days, to: startDate, options: NSCalendar.Options())! 148 | if date.compare(endDate) == .orderedDescending 149 | { 150 | break 151 | } 152 | dayCount += 1 153 | 154 | let dateNew = dateFormatter.string(from: date) 155 | arrDates.add(dateNew) 156 | 157 | } 158 | 159 | return arrDates 160 | } 161 | func getTimes(_ strStartTime : String,strEndTime : String, durationInMinutes : Int,is24HoursFormat : Bool) -> NSArray 162 | { 163 | let arrTimes = NSMutableArray() 164 | let cal = Calendar.current 165 | var days = DateComponents() 166 | var daymin = 0 167 | let dateFormatter = DateFormatter() 168 | if(is24HoursFormat == true) 169 | { 170 | dateFormatter.dateFormat = "HH:mm:ss" 171 | }else 172 | { 173 | dateFormatter.dateFormat = "hh:mm:ss a" 174 | } 175 | 176 | 177 | var strstartTime_new = strStartTime.replacingOccurrences(of: " ", with: "") 178 | strstartTime_new = strstartTime_new.replacingOccurrences(of: "AM", with: "") 179 | strstartTime_new = strstartTime_new.replacingOccurrences(of: "PM", with: "") 180 | strstartTime_new = strstartTime_new.replacingOccurrences(of: "am", with: "") 181 | strstartTime_new = strstartTime_new.replacingOccurrences(of: "pm", with: "") 182 | 183 | var strendTime_new = strEndTime.replacingOccurrences(of: " ", with: "") 184 | strendTime_new = strendTime_new.replacingOccurrences(of: "AM", with: "") 185 | strendTime_new = strendTime_new.replacingOccurrences(of: "PM", with: "") 186 | strendTime_new = strendTime_new.replacingOccurrences(of: "am", with: "") 187 | strendTime_new = strendTime_new.replacingOccurrences(of: "pm", with: "") 188 | 189 | 190 | 191 | let date1 = Date() 192 | let calendar = Calendar(identifier: Calendar.Identifier.gregorian) 193 | 194 | //start date 195 | var components = (calendar as NSCalendar).components([.year, .month, .day], from: date1) 196 | let arrayTime = strstartTime_new.components(separatedBy: ":") as NSArray 197 | components.hour = Int(arrayTime.object(at: 0) as! String)! 198 | components.minute = Int(arrayTime.object(at: 1) as! String)! 199 | let startDate = calendar.date(from: components) 200 | 201 | //end date 202 | var componentsEnd = (calendar as NSCalendar).components([.year, .month, .day], from: date1) 203 | let arrayTimeEnd = strendTime_new.components(separatedBy: ":") as NSArray 204 | componentsEnd.hour = Int(arrayTimeEnd.object(at: 0) as! String)! 205 | componentsEnd.minute = Int(arrayTimeEnd.object(at: 1) as! String)! 206 | let endDate = calendar.date(from: componentsEnd) 207 | while true 208 | { 209 | // days.hour = dayCount 210 | days.minute = daymin 211 | let date:Date = (cal as NSCalendar).date(byAdding: days, to: startDate!, options: NSCalendar.Options())! 212 | if date.compare(endDate!) == .orderedDescending 213 | { 214 | break 215 | } 216 | daymin += durationInMinutes 217 | let newDate = dateFormatter.string(from: date) 218 | arrTimes.add(newDate) 219 | 220 | } 221 | 222 | return arrTimes 223 | } 224 | 225 | func calculateTotalMinutes(_ strStartTime : String,strEndTime : String)->Int 226 | { 227 | var strstartTime_new = strStartTime.replacingOccurrences(of: " ", with: "") 228 | strstartTime_new = strstartTime_new.replacingOccurrences(of: "AM", with: "") 229 | strstartTime_new = strstartTime_new.replacingOccurrences(of: "PM", with: "") 230 | strstartTime_new = strstartTime_new.replacingOccurrences(of: "am", with: "") 231 | strstartTime_new = strstartTime_new.replacingOccurrences(of: "pm", with: "") 232 | 233 | var strendTime_new = strEndTime.replacingOccurrences(of: " ", with: "") 234 | strendTime_new = strendTime_new.replacingOccurrences(of: "AM", with: "") 235 | strendTime_new = strendTime_new.replacingOccurrences(of: "PM", with: "") 236 | strendTime_new = strendTime_new.replacingOccurrences(of: "am", with: "") 237 | strendTime_new = strendTime_new.replacingOccurrences(of: "pm", with: "") 238 | 239 | let arrStartData = strstartTime_new.components(separatedBy: ":") as NSArray 240 | let intStratHour = Int(arrStartData.object(at: 0) as! String)! * 60 241 | let totalstartMin = intStratHour + Int(arrStartData.object(at: 1) as! String)! 242 | 243 | let arrEndData = strendTime_new.components(separatedBy: ":") as NSArray 244 | let intEndHour = Int(arrEndData.object(at: 0) as! String)! * 60 245 | let totalEndMin = intEndHour + Int(arrEndData.object(at: 1) as! String)! 246 | 247 | 248 | 249 | var newHours = 0 250 | if(totalstartMin > totalEndMin) 251 | { 252 | newHours = totalstartMin - totalEndMin 253 | 254 | }else if (totalEndMin > totalstartMin) 255 | { 256 | newHours = totalEndMin - totalstartMin 257 | } 258 | 259 | return newHours 260 | } 261 | //MARK: CALENDAR FUNCTION 262 | func dayOfWeek(_ date : Date)->Int 263 | { 264 | 265 | let myCalendar = Calendar(identifier: Calendar.Identifier.gregorian) 266 | let myComponents = (myCalendar as NSCalendar).components(.weekday, from: date) 267 | let weekDay = myComponents.weekday 268 | return weekDay! 269 | } 270 | func startDateOfMonth(_ date : Date)->Date 271 | { 272 | let calendar = Calendar.current 273 | let myComponents = (calendar as NSCalendar).components([.year, .month], from: date) 274 | let startOfMonth = calendar.date(from: myComponents)?.addingTimeInterval(-1) 275 | return startOfMonth! 276 | } 277 | func dateByAddingMonths(_ monthsToAdd: Int,selectedDate : Date) -> Date? 278 | { 279 | 280 | let calendar = Calendar.current 281 | var months = DateComponents() 282 | months.month = monthsToAdd 283 | return (calendar as NSCalendar).date(byAdding: months, to: selectedDate, options: NSCalendar.Options(rawValue: 0)) 284 | } 285 | func dateByAddingWeeks(_ weeksToAdd: Int,selectedDate : Date) -> Date? 286 | { 287 | let calendar = Calendar.current 288 | var months = DateComponents() 289 | months.weekOfMonth = weeksToAdd 290 | return (calendar as NSCalendar).date(byAdding: months, to: selectedDate, options: NSCalendar.Options(rawValue: 0)) 291 | } 292 | 293 | func dateByAddingDays(_ daysToAdd: Int,selectedDate : Date) -> Date? 294 | { 295 | let calendar = Calendar.current 296 | var months = DateComponents() 297 | months.day = daysToAdd 298 | return (calendar as NSCalendar).date(byAdding: months, to: selectedDate, options: NSCalendar.Options(rawValue: 0)) 299 | } 300 | 301 | func endDateOfMonth(_ date : Date) -> Date 302 | { 303 | 304 | let calendar = Calendar.current 305 | let plusOneMonthDate = dateByAddingMonths(1,selectedDate: date) 306 | let plusOneMonthDateComponents = (calendar as NSCalendar).components([.year , .month], from: plusOneMonthDate!) 307 | let endOfMonth = calendar.date(from: plusOneMonthDateComponents)?.addingTimeInterval(-1) 308 | return endOfMonth! 309 | } 310 | 311 | //MARK: TIME AGO 312 | func shortDescriptionOfTime(_ date :Date)->String 313 | { 314 | 315 | let deltaSeconds = Int(Date().timeIntervalSince(date)) 316 | let deltaMinutes = deltaSeconds / 60 317 | 318 | var value: Int! 319 | 320 | if deltaSeconds < kMinute 321 | { 322 | // Seconds 323 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: deltaSeconds), NSDateTimeAgoLocalizedStrings("s")) 324 | 325 | } else if deltaMinutes < kMinute { 326 | // Minutes 327 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: deltaMinutes), NSDateTimeAgoLocalizedStrings("m")) 328 | } else if deltaMinutes < kDayMinutes { 329 | // Hours 330 | value = Int(floor(Float(deltaMinutes / kMinute))) 331 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: value), NSDateTimeAgoLocalizedStrings("h")) 332 | } else if deltaMinutes < kWeek { 333 | // Days 334 | value = Int(floor(Float(deltaMinutes / kDayMinutes))) 335 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: value), NSDateTimeAgoLocalizedStrings("w")) 336 | } else if deltaMinutes < kMonth { 337 | // Weeks 338 | value = Int(floor(Float(deltaMinutes / kWeek))) 339 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: value), NSDateTimeAgoLocalizedStrings("d")) 340 | } else if deltaMinutes < kYear { 341 | // Month 342 | value = Int(floor(Float(deltaMinutes / kMonth))) 343 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: value), NSDateTimeAgoLocalizedStrings("mo")) 344 | } 345 | 346 | // Years 347 | value = Int(floor(Float(deltaMinutes / kYear))) 348 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: value), NSDateTimeAgoLocalizedStrings("yr")) 349 | } 350 | 351 | func midiumDescriptionOfTime(_ date :Date)->String 352 | { 353 | 354 | let deltaSeconds = Int(Date().timeIntervalSince(date)) 355 | let deltaMinutes = deltaSeconds / 60 356 | 357 | var value: Int! 358 | 359 | if deltaSeconds < kMinute 360 | { 361 | // Seconds 362 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: deltaSeconds), NSDateTimeAgoLocalizedStrings("second")) 363 | 364 | } else if deltaMinutes < kMinute { 365 | // Minutes 366 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: deltaMinutes), NSDateTimeAgoLocalizedStrings("minute")) 367 | } else if deltaMinutes < kDayMinutes { 368 | // Hours 369 | value = Int(floor(Float(deltaMinutes / kMinute))) 370 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: value), NSDateTimeAgoLocalizedStrings("hour")) 371 | } else if deltaMinutes < kWeek { 372 | // Days 373 | value = Int(floor(Float(deltaMinutes / kDayMinutes))) 374 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: value), NSDateTimeAgoLocalizedStrings("day")) 375 | } else if deltaMinutes < kMonth { 376 | // Weeks 377 | value = Int(floor(Float(deltaMinutes / kWeek))) 378 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: value), NSDateTimeAgoLocalizedStrings("week")) 379 | } else if deltaMinutes < kYear { 380 | // Month 381 | value = Int(floor(Float(deltaMinutes / kMonth))) 382 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: value), NSDateTimeAgoLocalizedStrings("month")) 383 | } 384 | 385 | // Years 386 | value = Int(floor(Float(deltaMinutes / kYear))) 387 | return String(format:"%@%@", stringFromFormat("%%d%@", withValue: value), NSDateTimeAgoLocalizedStrings("year")) 388 | } 389 | 390 | func longDescriptionOfTime(_ date :Date)->String 391 | { 392 | 393 | let deltaSeconds = Int(Date().timeIntervalSince(date)) 394 | let deltaMinutes = deltaSeconds / 60 395 | 396 | var value: Int! 397 | 398 | if deltaSeconds < 5 { 399 | // Just Now 400 | return NSDateTimeAgoLocalizedStrings("just now") 401 | } else if deltaSeconds < kMinute { 402 | // Seconds Ago 403 | return String(format:"%@%@", stringFromFormat("%%d %@", withValue: deltaSeconds), NSDateTimeAgoLocalizedStrings("seconds ago")) 404 | } else if deltaSeconds < 120 { 405 | // A Minute Ago 406 | return NSDateTimeAgoLocalizedStrings("one minute ago") 407 | } else if deltaMinutes < kMinute { 408 | // Minutes Ago 409 | return String(format:"%@%@", stringFromFormat("%%d %@", withValue: deltaMinutes),NSDateTimeAgoLocalizedStrings("minutes ago")) 410 | } else if deltaMinutes < 120 { 411 | // An Hour Ago 412 | return NSDateTimeAgoLocalizedStrings("one Hour ago") 413 | } else if deltaMinutes < kDayMinutes { 414 | // Hours Ago 415 | value = Int(floor(Float(deltaMinutes / kMinute))) 416 | return String(format:"%@%@", stringFromFormat("%%d %@", withValue: value), NSDateTimeAgoLocalizedStrings("hours ago")) 417 | } else if deltaMinutes < (kDayMinutes * 2) { 418 | // Yesterday 419 | return NSDateTimeAgoLocalizedStrings("yesterday") 420 | } else if deltaMinutes < kWeek 421 | { 422 | // Days Ago 423 | value = Int(floor(Float(deltaMinutes / kDayMinutes))) 424 | return String(format:"%@%@", stringFromFormat("%%d %@", withValue: value), NSDateTimeAgoLocalizedStrings("days ago")) 425 | } else if deltaMinutes < (kWeek * 2) 426 | { 427 | // Last Week 428 | return NSDateTimeAgoLocalizedStrings("last week") 429 | } else if deltaMinutes < kMonth { 430 | // Weeks Ago 431 | value = Int(floor(Float(deltaMinutes / kWeek))) 432 | 433 | return String(format:"%@%@", stringFromFormat("%%d %@", withValue: value), NSDateTimeAgoLocalizedStrings("weeks ago")) 434 | } else if deltaMinutes < (kDayMinutes * 61) { 435 | // Last month 436 | return NSDateTimeAgoLocalizedStrings("last month") 437 | } else if deltaMinutes < kYear { 438 | // Month Ago 439 | value = Int(floor(Float(deltaMinutes / kMonth))) 440 | return String(format:"%@%@", stringFromFormat("%%d %@", withValue: value), NSDateTimeAgoLocalizedStrings("months ago")) 441 | 442 | } else if deltaMinutes < (kDayMinutes * (kYear * 2)) { 443 | // Last Year 444 | return NSDateTimeAgoLocalizedStrings("last year") 445 | } 446 | 447 | // Years Ago 448 | value = Int(floor(Float(deltaMinutes / kYear))) 449 | return String(format:"%@%@", stringFromFormat("%%d %@", withValue: value),NSDateTimeAgoLocalizedStrings("years ago")) 450 | 451 | } 452 | 453 | fileprivate func NSDateTimeAgoLocalizedStrings(_ key: String) -> String { 454 | 455 | return NSLocalizedString(key,comment:"") 456 | 457 | } 458 | fileprivate func stringFromFormat(_ format: String, withValue value: Int) -> String { 459 | 460 | let localeFormat = String(format: format, getLocaleFormatUnderscoresWithValue(Double(value))) 461 | let localizedString = localeFormat 462 | return String(format: localizedString, value) 463 | } 464 | 465 | fileprivate func getLocaleFormatUnderscoresWithValue(_ value: Double) -> String { 466 | 467 | let localeCode = Locale.preferredLanguages.first 468 | 469 | if localeCode == "ru" { 470 | let XY = Int(floor(value)) % 100 471 | let Y = Int(floor(value)) % 10 472 | 473 | if Y == 0 || Y > 4 || (XY > 10 && XY < 15) { 474 | return "" 475 | } 476 | 477 | if Y > 1 && Y < 5 && (XY < 10 || XY > 20) { 478 | return "_" 479 | } 480 | 481 | if Y == 1 && XY != 11 { 482 | return "__" 483 | } 484 | } 485 | 486 | return "" 487 | } 488 | 489 | } 490 | //********************Intput************************** 491 | 492 | // let startnewDate = dateOpertaion.dateFromString("15/5/2015", strDateFormat: "dd/MM/yyyy") 493 | // let endnewDate = dateOpertaion.dateFromString("18/5/2016", strDateFormat: "dd/MM/yyyy") 494 | // let selectedDate = dateOpertaion.dateFromString("18/5/2016", strDateFormat: "dd/MM/yyyy") 495 | 496 | // printLog(dateOpertaion.stringFromDate(NSDate(), strDateFormat: "EEEE MMMM yyyy hh:mm")) 497 | // printLog(dateOpertaion.dateFromString("22/12/2015 12:00:05", strDateFormat: "dd/MM/yyyy hh:mm:ss")) 498 | // printLog(dateOpertaion.timestampFromDate(NSDate())) 499 | // printLog(dateOpertaion.timestampFromDateString("01/01/2017")) 500 | // printLog(dateOpertaion.dateFromTimestamp(1453293776)) 501 | // printLog(dateOpertaion.stringFromTimestamp(1453293776,strDateFormat: "dd MMMM yyyy")) 502 | // printLog(dateOpertaion.convertUTCToLocaleTimeZone(NSDate())) 503 | // printLog(dateOpertaion.convertLocaleToUTCTimeZone(NSDate())) 504 | // printLog(dateOpertaion.isDateExist(StartDate: startnewDate!, EndDate: endnewDate!, selectedDate: selectedDate!)) 505 | // printLog(dateOpertaion.calculateTotalMinutes("1:00 PM", strEndTime: "5:00 AM")) 506 | // printLog(dateOpertaion.endDateOfMonth(startnewDate!)) 507 | // printLog(dateOpertaion.startDateOfMonth(startnewDate!)) 508 | // printLog(dateOpertaion.dayOfWeek(NSDate())) 509 | // printLog(dateOpertaion.dateByAddingMonths(-1, selectedDate: startnewDate!)) 510 | // printLog(dateOpertaion.dateByAddingWeeks(-2, selectedDate: endnewDate!)) 511 | // printLog(dateOpertaion.dateByAddingDays(-5, selectedDate: startnewDate!)) 512 | // printLog(dateOpertaion.getTimes("1:00 AM", strEndTime: "18:00 PM", durationInMinutes:60, is24HoursFormat: false)) 513 | // printLog(dateOpertaion.getDates(startnewDate!, endDate: endnewDate!, strDateFormat: "dd/MM/yyyy")) 514 | // printLog(dateOpertaion.longDescriptionOfTime(startnewDate!)) 515 | // printLog(dateOpertaion.shortDescriptionOfTime(startnewDate!)) 516 | 517 | 518 | 519 | 520 | //***********Add below strings in application's localizable file************** 521 | 522 | // "second" = "s"; 523 | // "minute" = "m"; 524 | // "hour" = "h"; 525 | // "week" = "w"; 526 | // "day" = "d"; 527 | // "month" = "mo"; 528 | // "year" = "yr"; 529 | // 530 | // "justNow" = "Just now"; 531 | // "secondsAgo" = "seconds ago"; 532 | // "oneminuteAgo" = "A minute ago"; 533 | // "minutesAgo" = "minutes ago"; 534 | // "oneHourAgo" = "An hour ago"; 535 | // "hoursAgo" = "hours ago"; 536 | // "yesterday" = "Yesterday"; 537 | // "daysAgo" = "days ago"; 538 | // "lastWeek" = "Last week"; 539 | // "weeksAgo" = "weeks ago"; 540 | // "lastMonth" = "Last month"; 541 | // "monthsago" = " months ago"; 542 | // "lastYear" = "Last Year"; 543 | // "yearsAgo" = "years ago"; 544 | 545 | //*************** 546 | 547 | 548 | --------------------------------------------------------------------------------