0

In my application i have worked for some part of the next version implementations,

So we need to prevent those some implementations for this version.

our superiors asked me to do with pre macro processor, having #ifDef, endif like that and you need to define the version number in buildsettings as preprocessor macro

I have added a user defined setting 'App_Version' in build Setting,

enter image description here

" How do i use it like

#ifDef AppVersion 1.0
NSLOG (current version implementation)
else
NSLOG (NEXT version implementation)

Actually i was not much awair on it, so that my interpretation was poor

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2732294
  • 641
  • 2
  • 10
  • 21

2 Answers2

1
#if App_Version == 1.0

I don't remember exactly how new preprocessor macros are defined in XCode but I don't think that you are defining it correctly. See How do I define preprocessor macros in Xcode 4?

However, using preprocessor macros for such things is far from recommended.

You should

  1. Create a method that will read the application version from the bundle
  2. Call the method to check version and use standard if-elseif-else

With iPhone development I can't really imagine why would you use such a macro/method though. How many versions of an app do you want to build? All the applications I have implemented for iOS needed only 1 version - the latest one. I don't see any reason why would you like to build an older application version from current code.

Use a versioning system and if you are implementing features for the next version into current code, use a dedicated branch! Otherwise it's just a mess and your supervisor is ... not smart ... for not seeing it.

Community
  • 1
  • 1
Sulthan
  • 128,090
  • 22
  • 218
  • 270
1

The compiler doesn't need (or want) to know anything about application version (it is information for the application submission process). This should not be done with preprocessor macros, unless you want to define your own (even then, I wouldn't recommend it). You should check the application version at runtime

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

and prevent new features from being accessible in the current version based on that. More generally I would consider using branching models like git flow to handle things like that. What will happen when you have 3,4,5 ... versions to handle. The preprocessor macros will become a nightmare to manage.

jbat100
  • 16,757
  • 4
  • 45
  • 70