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.
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
Post a Comment