The things that IOS #ifdef

Source: Internet
Author: User


The format is a bit messy, the whole several times can not be the whole, we will do it.

This article is I (I am a rookie) in the first contact with the launch of the project encountered a problem that I remember deeply.

If you are the great God, then please bypass, this is only a very superficial point of knowledge, write to yourself also share to everyone.

I believe you are not unfamiliar with the following statement.

#ifdef (1)

(2)

#else

(3)

#endif

But I'll explain it a little bit here (it looks professional), if there is a #define(1) execution before this formula ( 2) otherwise (3)

If that's the only point, then I'm sorry for the audience. Here's what I'm going to say.

I have a few words in my recent project code.

#ifdef DEBUG

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

#else

Static nsstring *const kfpbaseurl =@ "http:/(2)";

#endif

I believe that basically every project will have these words

I see very simple, yes, is very simple, is a test server address and production server address switch.

But the problem is #ifdef debug , because to change to the production server test, so I began to find #defineDebug

But I looked all over the project and didn't find it, and I was wondering. So how do you switch? Then I had to be pointed out.

Originally this #defineDebug can be considered Xcode integration, in fact, when we run the project can have the option to run DEBUG or release version.

How to choose? As






For example, if you choose Debug Compile, the system created itself #defineDebug and then you know the following ...

It may be easy for experienced people to do this, but it's a bit of a help if we don't have the experience or the attention.


What I would like to say here is that there will definitely be a test server and a production server in the project, and the address interface must be different when requested.

If you don't want trouble when you need to switch servers to change multiple places (and prone to errors), then I suggest you just have to involve the request interface in this one place

Replacement and modification. The advantage of this is to change a place, all will change, and not easy to make mistakes, you have any reason not to pay attention to it?


All right, here we go today. There is a mistake to welcome correct, communication -- LC. Mo widly





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.