.pch ํ์ผ์ด๋?
Precompile Prefix Header๋ก ๋ฏธ๋ฆฌ ์ปดํ์ผ ๋ ํค๋๋ก ์ปดํ์ผ ์๊ฐ์ ๋จ์ถ์ํค๋ ์ญํ ์ ํ๋ ํ์ผ์ ๋๋ค.
ํด๋น ํ์ผ์ ์ถ๊ฐํด์ฃผ๋ ์ฝ๋๋ค์ ๋ชจ๋ ํ์ผ์ ํฌํจ๋์ด ์ปดํ์ผ๋ฉ๋๋ค.
*ObjectiveC ํ๋ก์ ํธ์๋ง ์กด์ฌ, Swift์์๋ ์ฌ์ฉํ์ง ์์ต๋๋ค. ์ด์ ๋ ์๋ ๋งํฌ๋ก~
Why .pch file not available in swift?
In swift, Prefix.pch file is not provided. In my project, I want to declare some macros globally and use through out application. Can anyone give me suggestion how to do it, Where to declare? Is ...
stackoverflow.com
prefixheader.pch ์ถ๊ฐํ๊ธฐ
1. pch ํ์ผ ์ถ๊ฐํ๊ธฐ
New File -> PCH File ์ถ๊ฐ.
ํต์์ ์ธ ํ์ผ๋ช ์ ProjectName-PrefixHeader.pch๋ก ์ ํจ. ์ ๋ ๊ทธ๋ฅ PrefixHeader.pch๋ก....

2. Project - Build Settings (๊ฒ์: prefix header) ์์
Apple Clang - Language ํญ๋ชฉ์์ Prefix Header ์ค์ ์ ํด์ค๋๋ค.
Precompile Prefix Header --> (Yes๋ก ๋ณ๊ฒฝ)
Prefix Header์ .pch ํ์ผ ๊ฒฝ๋ก ์ถ๊ฐ --> (your-project-name/ConstantsTest-PrefixHeader.pch)

[์ฌ์ฉ ์์ ]
โ๏ธ PrefixHeader.pch ํ์ผ ์์ ํ๋ก์ ํธ ์ ์ฒด์์ ์ฌ์ฉํ ๊ฐ ๋๋ ์ค์ ๋ฑ์ ์์ฑํฉ๋๋ค.
import, define ๋ฑ ์์ฑ,,,
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
#import <UIKit/UIKit.h>
//ERROR code
#define E10001 @"๋คํธ์ํฌ ์ค๋ฅ"
//Manager
#import "DBManager.h"
#endif /* PrefixHeader_pch */
โ๏ธ ํธ์ถ
#import "DBManager.h" ์ถ๊ฐํ๋ฉด, ๋ค๋ฅธ ํ์ผ์์ ์ํฌํธ ํ์ง ์์๋ ์ด๋์ ๊ฐ์๋ DBManagerํด๋์ค์ ํจ์๋ ๋ณ์๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋ํ, ํ๋ก์ ํธ ์ ์ฒด์์ ์ฌ์ฉํ ๊ฐ๋ค์ #define๋ฌธ์ผ๋ก ์ ์ธํ์ฌ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController{
//import ํ์ง์์๋ ์ฌ์ฉ๊ฐ๋ฅ
UserModel *loginDt;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%@", E10001); // ๋คํธ์ํฌ ์ค๋ฅ
}
@end