How can I access a user-defined Xcode build setting?

前端 未结 6 882
忘了有多久
忘了有多久 2020-12-13 00:24

If I added a user-defined setting in my build configuration, how can I read that setting in my Objective-C code?

I have two files in my project, debug.plist

6条回答
  •  伪装坚强ぢ
    2020-12-13 00:53

    You can access your user-defined build setting at run-time (as suggested in a comment by @JWWalker)

    1. Add an entry to your Info.plist file, and set it to your User-defined Build Setting

      MySetting -> ${MYSETTING}
      
    2. Read its value from code

      Objective-C

      [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MySetting"];
      

      [Edit] Swift

      guard let mySetting = 
        Bundle.main.object(forInfoDictionaryKey: "MySetting") as? String 
          else { print("MySetting not found") }
      

提交回复
热议问题