Core Level File Structure That Needs To Follow For iOS App Development

Priyank Trivedi, in Priyank TrivediiOS App Developer Guide,iOS App Development,iPhone Mobile Application Development

Core level file structureThis tutorial covers the prerequisites needed to develop an iOS app and helps you in setting up a development environment for your project. I am going to explain basic things like what core level files and structure you need while creating your app.While developing an application for the first time, you might be confused about primary requirements for the development. So, this blog will help beginners and intermediate developers in developing an iOS app development. In this tutorial, I have assumed that you are familiar with the iOS programming language. You do not need to be a master to complete, but you will get more lessons if you comfortably read and understand this.1. Localization fileiOS users are from different countries and speak different languages, so to deliver a great user experience, you may want to make your app available in multiple languages. You can develop your application in multiple languages using localization. I am describing the type of data that can be stored and how it will be used in development. We can store all static messages, static array and alert of the application.Localizable.strings(English)//MARK: - Arrays - "arrGender" = "Male,Female,Other";//MARK: - Message -"LOGINSUCCESS" = "You have successfully loggedIn";ViewController.swiftlet arrGender = NSLocalizedString("arrGender", comment: "Array Gender").components(separatedBy: ",")2. TextMessage.swiftIf our application is not supporting multiple languages then this file is used to store all static messages and alert of the app. We are using many alert messages for the end user guidance, so, we need to store it in the file called TextMessage.swift.So, if you want to update any message then you need to make changes in this file only. This file will smooth the process of fetching, updating and deleting the messages from an app.TextMessage.swift
  • let LOGOUT = "Are you sure you want to Logout?"
  • let BLOCKUSER = "Are you sure you want to block this user?"
3. Constant.swiftThis file is used to store all constant value which can be used in the whole application. It also stores objects of singleton classes.Constant.swift
  • let APPNAME = "iphoneDemoSwift"
  • let APPDELEGATE = UIApplication.shared.delegate as! AppDelegate
  • let USERDEFAULTS = UserDefaults.standard
4. AppStructure.swiftThis file is used to store all enums, structures which will be used in our application. We can store any type of structure in this file as we feel it will be used globally in the project.It stores Structure of:
  • Screen size.
  • Device Type. i.e iphone 5, 6, 6+, etc.
  • Storyboard identifiers. We have more than one storyboard in our project we can create a combined structure of it.
  • View Controller identifiers.
  • Segues identifiers. It is a best practice to write segue identifier in the structure at the same time while we drag it in the project. By creating a structure we can easily access it anywhere in the project.
  • TableCell identifiers.
  • Web Service list.
  • Font name and style. We are using a specific font in our app, It is a good practice to create a structure of it, so we can easily access it at coding time.
  • App Theme colors.
  • Character set. We are using many custom character set when we want to restrict user input, so it can be also done using the structure of it.
  • Date Format. We can store different date formats for later use.
AppStrcuture.Swiftstruct SegueID{static let SignUpToSignIn = "SignUpToSignIn"static let SingInToForgotPassword = "SingInToForgotPassword"static let MatchesToProfile = "MatchesToProfile"}ViewController.swiftself.performSegue(withIdentifier: SegueID.MatchesToProfile, sender: nil)5. Helper.swiftThis class is same as a Constant class but it will store methods, which can be used globally in any type of class like UIViewController, NSObject, etc. If the method is only used in View Controller then it's better to store it in BaseViewController.swift (explain later). This method can be called without any instance of the class. We can store method like show alert, show/hide loader, etc.Helper.Swiftfunc UIColorFromRGB(_ rgbValue: UInt) -> UIColor{return UIColor(red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,blue: CGFloat(rgbValue & 0x0000FF) / 255.0,alpha: CGFloat(1.0))}ViewController.Swiftself.navigationView.backgroundColor = UIColorFromRGB(0x4CAF50)6. BaseViewController.swiftBaseViewController is a base class for all your custom view controllers. It is a subclass of UIViewController. For all of your view controller, you have to set BaseViewController as a root view controller instead of UIViewController. This will reduce code redundancy in the project. There are many methods that will be used in more than one view controller, that methods should be stored in BaseViewController. The methods which are defined in BaseViewController can be easily accessed without any instance of the class.In the app there may be a requirement of sending mail from multiple screens. In this case, instead of implementing Mail Delegate methods individually, we can define it in BaseViewController and can use it in many ViewControllers.BaseViewController.swiftfunc emailWith(_ strSubject:String,strMessage:String,arrRecipients:[String]){if MFMailComposeViewController.canSendMail(){let picker: MFMailComposeViewController=MFMailComposeViewController()picker.mailComposeDelegate=self;picker.setSubject(strSubject)picker.setToRecipients(arrEmail)picker.setMessageBody(strMessage,isHTML: false)self.present(picker, animated: true, completion: nil)}}ViewController.swiftclass ViewController: BaseViewController{var arrString = [String]()arrString.append("aarti@inheritx.com")self.emailWith("This is subject", strMessage:"Check out this", arrRecipients:arrString)}7. AppTrash.swiftAt the time of development, we have commented multiple code blocks which can be used later. That code is not useful right now, but there are chances that it can be used in future. So, instead of storing all commented code in a class, it's a good practice to store it in AppTrash.swift, So we can use it later on when we need. This will make viewcontrollers more clear and readable. We can find it easily and put back it in respective file later on when we require.8. AppInfo.txtThis file is used to store app information i.e application name, about, version, basic feature, third party classes, custom classes, AppStore link (if an app is live) or any other app related information. This file will other developers to understand the application.I hope this tutorial has helped you to understand the basic fundamentals of creating apps with iOS platform. If you like this blog, please share it on your social media account and drop your comments below. Feel free to contact us, if you have any query or concern regarding this tutorial.For reference, you can download the demo project on Github.Thanks for reading!

Create Next-Gen Web & Mobile Apps With InheritX Solutions

Related post