Swift reads app version information and PCH files

Source: Internet
Author: User

Swift reads app version information

There is time we need to read the app version information such as configuration information, so we can use the method: Nsbundle.mainbundle (). Infodictionary to get

Example:
Swift
Let infodictionary = Nsbundle.mainbundle (). infodictionary
Let shortversion = infodictionary! ["Cfbundleshortversionstring"]
Print (shortversion!)
PCH file

PCH file name:

Generally named after the project name, that is, what the project name is, PCH file also called what name.

PCH principle:

The contents of the PCH file are shared by all files in the project.

PCH Tips:

1.pch need to compile in advance, in the engineering file, find build Setting, select the All option, found under the Apple LLVM 1.7–language collection: Precompile Prefix Header set to Yes, then Prefix The absolute path to write the PCH file in the Header option,

2. Find the Swift Compiler–code Generation collection from which to configure the Objectie-c Bridge file: objective-c bridging Header, write the same PCH file path

3. Press Command+b to compile in Xcode
PCH file function:
Swift
/*
Preferred to determine whether there is currently a C file, if there is C does not import OC syntax
Each OC file header will be defined by default __OBJC__ this macro
*/
#ifdef __objc__
/**
1. Store some common macros
*/
#define Persimmon "Mr.cong"
/**
2. Store some common header files
*/
#import "Uiimage+test.h"
/**
3. Customize some debugging nslog (output log)
... Represents a variable parameter inside a macro
__VA_ARGS__ represents a variable parameter within a function
*/
#ifdef DEBUG
#define TLOG (...) NSLog (__va_args__)
#else
#define TLOG (...)
#endif

#endif

PCH drawbacks;

1. Need to compile ahead of time
2. Need to make some judgments to determine whether there is currently a C file, if there is C does not import OC syntax

Related Article

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.