IOS # ifdef

Source: Internet
Author: User


The format is a bit messy. It won't be enough for a few times.

This article is a memorable question I encountered when I first came into contact with the launch project.

If you are a great God, Please bypass it. This is just a superficial knowledge point and you can share it with yourself.

I believe you are familiar with the following statements.

# Ifdef (1)

(2)

# Else

(3)

# Endif

But here I will explain it a little (professional). If there is # define (1) before this formula, execute (2); otherwise, execute (3)

If this is the case, I am sorry for the audience. Now let's talk about my problems,

The project code I recently came into contact with includes the following:

# Ifdef DEBUG

Static NSString * const kFPBaseUrl = @ "http: // (1 )";

# Else

Static NSString * const kFPBaseUrl = @ "http: // (2 )";

# Endif

I believe there will be a few words in each project.

Let's take a look at it very easily. That is, it is a test server address and production server address switch.

But the problem lies in # ifdef DEBUG. to change it to a production server for testing, I will start looking for # defineDEBUG

But I couldn't find the entire project after searching for it, and I was wondering. So how to switch? Later, I got some help.

Previously, this # defineDEBUG can be regarded as Xcode integration. In fact, when running a project, we can choose to run debug or release.

How to choose? For example


<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + IDxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20140508/2014050808314271.jpg" alt = "\">


The system created # defineDEBUG on its own, and then you will understand it below...

This problem may be very easy for experienced people, but it is helpful for those who have no experience or have not paid attention to it.


Here, I would also like to mention that there will certainly be test servers and production servers in the project, and the address interfaces used for requests will certainly be different.

If you don't want to bother changing the server in multiple places (and it is prone to errors), I suggest you only involve the request interface in this place.

. The advantage of doing so is to change a place, and everything will change, and it is not easy to make mistakes. What reason do you have to pay attention?


Now, we are here today. If any error occurs, please correct it and contact us-LC. Mo liuyun





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.