Skip to main content

iOS App Basic 1

Here is simple helpful code for faster development. Using this you can increase development speed also helpful for the changes in app.

App Basic Info:

We can create on swift file named: "Structure.swift" in every project. In that file, add struct like this

struct App {

    static let name = "App Name" // App Name 
    static let delegate = UIApplication.shared.delegate as! AppDelegate // Instance of AppDelegate
    static let currentController = appDelegate.window?.rootViewController // Instance of current Root view controller
    
    // It give you the app version with build number
struct version { 

        static let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String

        static let appBuildNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String
        
        static let versionWithBuildNumber = "v. \(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String) (\(Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String))"

    }
    
// It is use to update the app badge from any where
    static func updateAppBadge(_ appBadge:Int) { 
        UIApplication.shared.applicationIconBadgeNumber = appBadge
    }
    
// You can add URLs app here
    struct urls {
        static let localServer = "<Local Server Url>"
        static let liveServer = "<Live Server Url>"
        static let appStoreURL = "<App Store Server Url>"
    }
}


How to use

print(App.name)

print(App.version.versionWithBuildNumber)

===============================================================
This is the very basic structure using this, you can overcome the issue of writing the object every where in code. Also you can add this type methods to every xcode project so you can do like plug and play kind of things. You can add/change as per your requirement. 

Comments

Popular posts from this blog

iOS App Basic 2

iOS App Basics 2 Here is the second post for some functions for basic code makes easy. Create the one Extension file for few basic feature like below: -> Create Extension.swift file in App Basic folder. 1. This extension is used to add max length of TextField entry. extension UITextField {     @IBInspectable var maxLength: Int         {                  get {             guard let length = maxLengths[ self ] else {                 return Int.max             }             return length         }         set {             maxLengths[ self ] = newValue                          addTarget( self , act...

iOS App Basic 3

Basic & Great useful cocoa pods. Hello friends, I am here again with new great basic step for iOS coding. Here I want to discuss some more cocoa pods which is used for easier development. 1. R.Swift It is wonderful pods which use to get rid of many thing like need to remember the image name, controller segue name, fonts, storyboard names, nib name, reusable cells and some more. This pods create auto instance of the image from assets and create UIImage instance which can be use throughout the project by simply writing single line of code. For Example: After installation and setup of R.Swift You have one image name "ic_setting" in your image assets. You just have to write the below line only let image = R.image.ic_setting() ?? UIImage() This will return UIImage, you can directly assign this image to Imageview. All the name will suggest by the Suggestion list. Same for the Segue self.performSegue(withIdentifier: R.segue.loginVC.segDashboard.identifi...