iOS Development-project configuration

Source: Internet
Author: User

New guidance, Danale bypass.
The purpose of this article is to illustrate some of the configurations that need to be perfected in the early stages of the app creation, and to reduce unnecessary development.

Main content:

    • New Project Creation
    • Grouping structure
    • Configuration file
    • Auxiliary classes
1. New Project Creation

As a rule, we start the Xcode development environment and use the single View application project template to create a new project, and here are a few items to keep in mind.

1.1 Fill in the item-specific prefix in class prefix

The Class Prefix field will help follow Apple's coding guidelines, because each class in the project needs to have a unique name. When you create a project, you can use the value of this field to define the default class name prefix, which is used when creating a new class. Although Apple's guidelines recommend a prefix of three characters, I usually use two characters as a prefix: After all, it's a coincidence. (But Apple retains all two characters of the right to use the ownership)

Also, after Xcode6, the Create project defaults to no class prefix option and No. pch file. So we need to create them manually. The steps are as follows:

    1. Class Prefix
      , select Project, the right-hand visible class Prefix, enter.
    2. . pch File
      1. Add File
      2. Set path

1.2 Create Local git Repository for the project/create git Repository on

Selecting this option will create a local git repository

When you select this option to create a local git repository, the Xcode tool automatically creates this repository for you, enabling you to use versioning in your project. With versioning, Xcode keeps track of changes to the source code, enabling you to roll back the code to a version, commit changes, compare code differences between different versions, and so on. If you are using an SVN (Subversion system)-based server to manage your source code, you can use the SVN client or the SVN command to manage the source code, so you do not need a local git repository. If you are not using SVN-based servers, it is highly recommended to select the Create Local git Repository option when creating a new project.

2. Grouping structure

A good practice is to use Grouping (group) in the project directory structure to organize different elements, such as images, sounds, classes, views, helpers, and so on.

Please create the following groupings in your project

    • Externals
    • Categories
    • Helpers
    • Definitions
    • Images

:

Because the grouping is just a container and not a physical folder that exists on the file system, these folders should also be created under the project root folder of the file system. :

Alternatively, we can create the write folder directly under the root folder and add it to the project.

3. Configuration files

The use of some common macros during iOS development can improve the efficiency of development and the reusability of code.
It is convenient to put these macros into a header file and then put them in the-prefix.pch file in the project for immediate use.

In the Project Explorer window, navigate to the definitions group and choose the New File option from the context menu. Create a C header file, and name it MyConstants.h.

You can then define the macro you want here.
Here are some of the macros I use most:

////MyConstants.h//Grouptest////Created by Colin on 15/1/31.//Copyright (c) 2015 Icephone. All rights reserved.//#ifndef Grouptest_myconstants_h#define GROUPTEST_MYCONSTANTS_H//-------------------Get the device size-------------------------//navbar Height#define Navigationbar_height//Get screen width, height#define SCREEN_WIDTH ([UIScreen mainscreen].bounds.size.width)#define Screen_height ([UIScreen mainscreen].bounds.size.height)//-------------------Get the device size-------------------------//----------------------Color class---------------------------//RGB color conversion (16->10 binary)#define UICOLORFROMRGB (rgbvalue) [Uicolor colorwithred: ((float) ((Rgbvalue & 0xFF0000) >> 16)/255.0 Green: ((float) ((Rgbvalue & 0xff00) >> 8)/255.0 Blue: ((float) (Rgbvalue & 0xFF))/255.0 alpha:1.0]//color settings with Rgba#define COLOR (R, G, B, A) [Uicolor colorwithred:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]//Get RGB color#define RGBA (r,g,b,a) [Uicolor colorwithred:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]#define RGB (r,g,b) RGBA (r,g,b,1.0f)//Background color#define Background_color [uicolor colorwithred:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]//Clear background color#define Clearcolor [Uicolor Clearcolor]#pragma mark-color functions#define RGBCOLOR (r,g,b) [Uicolor colorwithred: (r)/255.0f Green: (g)/255.0f Blue: (b) /255.0f alpha:1]#define RGBACOLOR (r,g,b,a) [Uicolor colorwithred: (r)/255.0f Green: (g)/255.0f Blue: (b)/255.0f Alpha: (a)]//----------------------Color class--------------------------//----------------------system----------------------------//Get System version#define Ios_version [[[Uidevice Currentdevice] systemversion] Floatvalue]#define Currentsystemversion [[Uidevice Currentdevice] systemversion]//Get current language#define CURRENTLANGUAGE ([[Nslocale preferredlanguages] objectatindex:0])//Determine if the retina screen, whether the device is iphone 5, is an ipad#define Isretina ([UIScreen instancesrespondtoselector: @selector (currentmode)]? Cgsizeequaltosize (Cgsizemake (640, 960), [[UIScreen Mainscreen] currentmode].size): NO)#define IPHONE5 ([UIScreen instancesrespondtoselector: @selector (currentmode)]? Cgsizeequaltosize (Cgsizemake (640, 1136), [[UIScreen Mainscreen] currentmode].size): NO)#define ISPAD (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)//Judging whether it is a real machine or a simulator#if Target_os_iphone//iphone Device#endif#if target_iphone_simulator//iphone Simulator#endif//Check the system version#define SYSTEM_VERSION_EQUAL_TO (v) ([[[Uidevice Currentdevice] systemversion] compare:v options:nsnum Ericsearch] = = nsorderedsame)#define System_version_greater_than (v) ([[[Uidevice Currentdevice] systemversion] compare:v options:nsnum Ericsearch] = = nsordereddescending)#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO (v) ([[[Uidevice Currentdevice] systemversion] compare:v options: Nsnumericsearch]! = nsorderedascending)#define System_version_less_than (v) ([[[Uidevice Currentdevice] systemversion] compare:v options:nsnum Ericsearch] = = nsorderedascending)#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO (v) ([[[Uidevice Currentdevice] systemversion] compare:v options: Nsnumericsearch]! = nsordereddescending)//----------------------system----------------------------#endif

As to how to use it, it was mentioned before, in the corresponding. pch file, you can import the header file.

If you import a header file in a. pch file, it is globally available.

#import <Availability.h>#ifdef __OBJC__   #import <UIKit/UIKit.h>   #import <Foundation/Foundation.h>   #import "MyConstants.h"#endif
4. Auxiliary class

Personal advice, create a replication class to implement some common static methods. This will greatly improve the development efficiency.
For example, use the value of the Nsuserdefaults class to read and write settings.

In the Project Explorer window, navigate to the Helpers group and select File from the context menu | New option. Create a new Objective-c class that inherits from the NSObject class, named Myconfigurationhelper, as follows:


Then add the following code:

MyConfigurationHelper.h

#import <Foundation/Foundation.h>  @interface myconfigurationhelper : nsobject + (BOOL) Getboolvalueforconfigurationkey: (NSString*) _objectkey;+ (NSString*) Getstringvalueforconfigurationkey: (NSString*) _objectkey;+ (void) Setboolvalueforconfigurationkey: (NSString*) _objectkey Withvalue: (BOOL) _boolvalue;+ (void) Setstringvalueforconfigurationkey: (NSString*) _objectkey Withvalue: (NSString*) _value;@end

Myconfigurationhelper.m

#import "MyConfigurationHelper.h"  @implementation myconfigurationhelper + (BOOL) Getboolvalueforconfigurationkey: (NSString*) _objectkey{//create An instance of Nsuserdefaults    Nsuserdefaults*defaults = [NsuserdefaultsStandarduserdefaults]; [Defaults synchronize];//let ' s Make sure the object is synchronized    return[Defaults Boolforkey:_objectkey];} + (NSString*) Getstringvalueforconfigurationkey: (NSString*) _objectkey{//create An instance of Nsuserdefaults    Nsuserdefaults*defaults = [NsuserdefaultsStandarduserdefaults]; [Defaults synchronize];//let ' s Make sure the object is synchronized    if([defaults stringforkey:_objectkey] = =Nil)    {//i don ' t want a (NULL) returned        return@""; }Else{return[Defaults Stringforkey:_objectkey]; }}+ (void) Setboolvalueforconfigurationkey: (NSString*) _objectkey Withvalue: (BOOL) _boolvalue{Nsuserdefaults*defaults = [NsuserdefaultsStandarduserdefaults]; [Defaults synchronize];//let ' s Make sure the object is synchronized[Defaults setbool:_boolvalue Forkey:_objectkey]; [Defaults synchronize];//make sure you ' re synchronized again}+ (void) Setstringvalueforconfigurationkey: (NSString*) _objectkey Withvalue: (NSString*) _value{Nsuserdefaults*defaults = [NsuserdefaultsStandarduserdefaults]; [Defaults synchronize];//let ' s Make sure the object is synchronized[Defaults setvalue:_value Forkey:_objectkey]; [Defaults synchronize];//make sure you ' re synchronized again}@end

The Myconfigurationhelper class contains a number of static methods that can help you access nsuserdefaults objects. It contains a method for obtaining (get) and setting (set) the value of the NSString type and the BOOL type, which makes the operation much simpler.
Also, you can define your own common methods.

iOS Development-project configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.