Swift

Swift - Configuration Settings File(.xcconfig ํŒŒ์ผ)์„ ์ด์šฉํ•œ git์— API Key ์ˆจ๊ธฐ๊ธฐ

iosos 2024. 11. 16. 15:39

๐Ÿ“‘ ํ•™์Šต ๋‚ด์šฉ

  • .xcconfig ํŒŒ์ผ์„ ์ด์šฉํ•˜์—ฌ API Key๋ฅผ git์— ๋…ธ์ถœ์‹œํ‚ค์ง€ ์•Š๋„๋ก ๋ฐฉ๋ฒ•
  • API Key๋Š” ๋ฏผ๊ฐํ•œ ์ •๋ณด์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ณด์•ˆ์„ ์œ„ํ•ด Info.plist ํŒŒ์ผ์— ์ €์žฅํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋ฉด ์ข‹์Œ

 

1. Configuration Settings File ์ƒ์„ฑ

 

 

2. API Key ์„ ์–ธ

 

 

3. info.plist์— API ํ‚ค ์ฐธ์กฐ

 

 

4. .xcconfig ํŒŒ์ผ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก Project Info์— Configuration ํŒŒ์ผ ์ถ”๊ฐ€

 

 

5. API Key ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

- Bundle.main.infoDictionary?[”API_KEY”] as? String ?? “” ์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ค๋ฉด ๋จ

    init() {
        if let key = Bundle.main.infoDictionary["API_KEY"] as? String ?? ""
            print("kakao key : \\(key)")
            let interceptor = AuthorizationInterceptor(kakaoKey: key)
            session = Session(interceptor : interceptor)
        } else {
            session = Session()
        }
    }

 

 

6. .gitignore ํŒŒ์ผ์— ์ถ”๊ฐ€

- '*.xcconfig' ์ถ”๊ฐ€

 

 

๐Ÿ“š ์ฐธ๊ณ  ์ž๋ฃŒ