All Questions
186
questions
117
votes
10
answers
78k
views
How can I convert from degrees to radians?
I am trying to convert this Obj-C code to Swift code but I don't know what the equivalent of this code should be ?
#define DEGREES_TO_RADIANS(degrees)((M_PI * degrees)/180)
I googled and found this
...
44
votes
2
answers
57k
views
What's the difference between #if and #ifdef Objective-C preprocessor macro?
How to define preprocessor macros in build settings, like IPAD_BUILD, and IPHONE_BUILD (and how to use them in my factory methods)?
I'm using these by heart now, would be cool to know what is going ...
31
votes
3
answers
31k
views
How to use Objective-C code with #define macros in Swift
I'm trying to use a third-party Objective-C library in a Swift project of mine. I have the library successfully imported into Xcode, and I've made a <Project>-Bridging-Header.h file that's ...
26
votes
6
answers
18k
views
What is the Swift preprocessor equivalent to iOS version check comparison?
I am getting
yld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings
and here's the function that is causing the error when the application is running on an iOS7 device and without even ...
15
votes
3
answers
17k
views
iOS Writing Macro detect 3.5 inch or 4 inch display [duplicate]
I am trying to write a macro to determine the device is 3.5 inch or 4 inch. Some thing similar below.
#define IOS_OLDER_THAN_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6....
12
votes
1
answer
5k
views
Xcode 7.3: "Ambiguous expansion of macro" when re-defining macro in prefix file
I am using Xcode 7.3, and I am getting an "Ambiguous expansion of macro" warning, for a macro which was defined in Foundation, but which I have undefined and re-defined in my prefix file. I have ...
10
votes
1
answer
387
views
ELEVENWORDINLINE when to use it?
I was always wondering what can I do with things like that:
ONEWORDINLINE(w1)
TWOWORDINLINE(w1, w2)
THREEWORDINLINE(w1, w2, w3)
up to
TENWORDINLINE(w1, w2, w3, w4, w5, w6, w7, w8, w9, w10)
...
9
votes
1
answer
3k
views
Preprocessor macro to target Interface Builder not available to OS X?
I have an IB_DESIGNABLE custom NSView subclass. When drawing, I want my view to perform a method only when it's being run in Interface Builder. I looked this up, and Apple's documentation states:
...
8
votes
2
answers
8k
views
How to define array in Macros in Objective-c?
Is there any possibility to define arrays in macro in objective-c.
8
votes
4
answers
8k
views
iOS create macro
I have a piece of code I'm using fairly often and would like to make a macro out of it. I'm not exactly sure how to do that though. Here's the code I want to use
UIImage *titleImage = [UIImage ...
7
votes
3
answers
2k
views
Unused parameter warning
I am getting "unused parameter 'testString'" warning from following code. But I am using testString to log. So how come it is unused ?
- (void)getString:(NSString *)testString {
ICELogInfo(...
7
votes
1
answer
657
views
How to use prepeocessor macros in storyboard elements?
I want to use pre-defined macros in StoryBoard elements
For example:
I have a 10 textfield in my app and if I want to change the size of all textfield through preprocessor macros then it will be ...
7
votes
5
answers
963
views
Macro capturing Self in block
I have a problem with the below macro which i use to log various bits of information
#define JELogVerbose(fmt, ...)
DDLogVerbose((@"%@ %@ - " fmt), NSStringFromClass([self class]),
...
6
votes
3
answers
3k
views
How can I replace a #define macro I used to have in Objective-C in SWIFT?
I've been using this macro in Objective-C:
#define RGBA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
I am trying to figure out how I can get the closest ...
6
votes
4
answers
1k
views
Get specific value of preprocessor macro
In my build settings i have define some preprocessor macros
i.e. SANDBOX_ENV=1
I want to use the value of SANDBOX_ENV in my shell script.
I have tried echo "SANDBOX value is = ${...
6
votes
4
answers
4k
views
Detecting iPhone6 & iPhone6 Plus using macros
I am attempting to detect whether the current device is iPhone5, iPhone6 or iPhone 6 Plus.
In my app I am already using this macro to detect iPhone 5 which works perfectly.
#define IS_IPHONE_5 (...
6
votes
2
answers
9k
views
Show Settings Bundle only for Debug Mode
I'm using this tutorial to create a simple Settings Bundle in my app.
The thing is that I want to hide the settings entirely in the release version and I cannot find a way to do it. I've read this ...
6
votes
3
answers
4k
views
Add macro BETA=1 to Xcode for certain schemes?
I want to add a new #define macro to my app, but only for certain schemes, like a beta scheme. What is the best way to do this? I know that when you are running the app in test (i.e. in simulator) it ...
6
votes
1
answer
6k
views
XCode 5.1 preprocessor macro not working
I cannot get this macro to compile the correct code.
Here is the code:
Here are the build settings (I'm doing a Release build):
Note that the GCC documentation says -Dname will define as 1, so I ...
6
votes
2
answers
1k
views
Xcode 8 and Preprocessor Macros
Since the latest XCode update 8.1 (Build 8B62) I'm having strange problems with syntax highlighting/code completion in connection with preprocessor macros.
They worked just fine with the XCode 8 GM ...
5
votes
2
answers
10k
views
Objective-C: "format string is not a string literal (potentially insecure)" warning with macro
I'm using a macro to simplify returning localised strings, like so:
#define GetLocalStr(key, ...) \
[NSString stringWithFormat:[[NSBundle mainBundle] localizedStringForKey:key value:@"" table:nil]...
5
votes
1
answer
3k
views
Macro condition for iOS and OSX code
I need to support iOS and OSX in my shared library, whats the best Macro / Practise for conditioning iOS and OSX code
the bellow code doesn't work for some reason :/
- (NSString *)hostName {
#...
4
votes
2
answers
3k
views
How to define a macro globally in Objective-C?
I want to define a macro globally. I want to override NSLocalizedString() throughout my whole project. Is that possible and how do I do it?
4
votes
2
answers
1k
views
Write macros for GCD calls?
I'd like to create a macro for GCD calls like for example:
dispatch_async(dispatch_get_main_queue(), ^{
stuff....
});
the macro could look something like this:
main(^{...})?
Not sure how to ...
4
votes
5
answers
5k
views
How to define a function macro to check key between multiple localized string files?
I have a Localizable.strings file for my project's i18n, and a lib uses KYLocalizable.strings.
I have considered to make Localizable.strings "subclass" from KYLocalizable.strings, but it cannot as ...
4
votes
1
answer
4k
views
Swift: Multiple targets handling: macros not working [duplicate]
from the reference How to handle multiple targets in XCode using swift language? and https://www.appcoda.com/using-xcode-targets/
I have created three targets, each target having different bundle ids ...
4
votes
1
answer
1k
views
Programmatically distinguish between Ad-hoc and AppStore version of app
I have an app that sends logs to Keen IO for logging and analysis purposes. The code that sends logs to Keen IO is guarded by preprocessor macros, and hence it never sends any logs when I’m running it ...
4
votes
4
answers
4k
views
#define in header files in Objective-C
I have a Global.h that looks like
#define NUMBERX 21
In AppDelegate.h I include the Global.h file. In the AppDelegate.m I include the AppDelegate.h file. But in the AppDelegate.m I can't access the ...
4
votes
1
answer
5k
views
objective C log method call [duplicate]
Possible Duplicate:
How to pass all arguments of a method into NSLog?
I can setup a macro printCommand to log the receiver and selector of a method call as follows:
#define printMethodCall NSLog ...
4
votes
0
answers
230
views
Best practices to define Xcode Preprocessor Macros for Multi Projects WorkSpace in iOS
I have a multiProject workspace in Xcode.
I would like to setup preprocessor Macros that are accessible for all my projects according to my main project target.
I have a MainProject with Target1 and ...
3
votes
1
answer
3k
views
How do I define a macro with variadic method in objective-C?
The method I am trying to call is;
- (void)addLogWithLevel:(MDCLogLevel)logLevel logContent:(NSString *)logContent, ...
{
va_list args;
va_start(args, logContent);
NSString *message = [[...
3
votes
1
answer
4k
views
When to use macros in Objective-C
According to definitions "A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro". I used to use macros for those codes which ...
3
votes
3
answers
2k
views
Swift + macro parameters
I read all Q&A related to Macros in Swift, And i did figure out that everything in Swift now global, Am i right?
And my actual question is that if i have a macro in which i need parameters to be ...
3
votes
3
answers
3k
views
XCode Preprocessor macro #if still includes code contrary that the symbol is defined to 0
I have a preprocessor macro in my XCODE project called LINPHONE_DEBUG. In my build settings, I have set the macro to 0 exactly like this: LINPHONE_DEBUG=0.
But somehow when I use this code:
#if ...
3
votes
3
answers
10k
views
Macro Recording in iOS
Is it possible to record set of touch events on iPhone and then playback?
I have searched alot but could not find any answer. if its possible, can anyone explain with an example.
I m not looking for ...
3
votes
1
answer
880
views
Detect whether iOS app is running Debug or Release build without preprocessor macros, for unit testing purposes?
I've seen plenty of answers and am familiar with using something preprocessor macros to check whether I'm in debug or release mode, but I'm keen to unit test around those scenarios, so I'd love a way ...
3
votes
1
answer
3k
views
Use of undeclared identifier for a macro
In my app i'm performing following steps
1) Created a .h file Say, GlobalMacros.h
In GlobalMacros.h
#define IP_ADDR @“SERVER_IP”
2) In my apps .pch file
import “GlobalMacros.h”
Then in rest of ...
3
votes
1
answer
673
views
iOS debugBlock macro
I'm sure alot of you are aware of the macro
#ifdef DEBUG
#define DebugLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [...
3
votes
1
answer
1k
views
Adopting os_log APIs while keeping backward compatibility
I'm trying to add support for the new logging and activity tracing APIs to a library in a way that maintains backward compatibility for users of the library who haven't yet adopted the latest version ...
3
votes
1
answer
361
views
Macros in iOS to give warning if method used is not available on minimum supported version
Recently I updated my Xcode to 6.3(sdk iOS8). I am using one API of NSString called "containsString" which is available from iOS 8.0 onwards. But my deployment target is 7.0 and this API is not ...
2
votes
1
answer
3k
views
Enabling ifdef macro used in the static library
Can you use macros defined in static libraries?
I have my own debug macro called TWDEBUG that I use in a static library I create for sharing.
If I import the static library to my new project and use ...
2
votes
3
answers
4k
views
Format specifies type 'int' but the argument has type 'NSString *'
Anyone:
I want to use one macro to print log, following,
#define isaObject(parameter) _Generic((parameter), id: YES, id __strong: YES, default: NO)
#define kNSLog(parameter) do \
...
2
votes
2
answers
1k
views
Global macros in Swift
What is the best way to use global macros in Swift (If this is what is called, english is not my mother tongue sorry). I am looking for a way to have all the macros/keys in on place, maybe a class.
...
2
votes
3
answers
1k
views
Inline function versus macro
I'm working on an iOS app using C and Objective-C, and I want to write a very small piece of code that will be executed thousands of times from more than one place. Is it safe to make this an inline ...
2
votes
3
answers
455
views
Dynamically turning on NSLogs
I am currently using the following DebugLog macro
#if defined(DEBUG) && defined(useDebugLogs)
#define DebugLog( s, ... ) NSLog( @"<%s:(%d)> %@", __PRETTY_FUNCTION__, __LINE__, [...
2
votes
2
answers
162
views
How to write a macro similar to CGRectZero for a custom struct
I have a custom struct and I'd like to have a define similar to CGRectZero.
This way I can have a void structure I can test against for not valid values.
2
votes
2
answers
2k
views
iOS, how to disable CERTAIN warning about deprecated methods [duplicate]
I'm moving from iOS6 to iOS7, but I want to keep the code that works for iOS6, so my code looks like this:
if (isiOS7orAbove) {
sizeios7 = [text boundingRectWithSize:CGSizeMake(TEXTVIEW_WIDTH, ...
2
votes
2
answers
504
views
Define a macro to replace code
I'm using TestFlight and I've got this macro to replace NSLog the the TestFlight remote logging equivalent.
#define NSLog(__FORMAT__, ...) TFLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, ...
2
votes
1
answer
440
views
Macro constant for something like status bar height
I know how to define constants and macros using C. Is there any way to define a constant in Objective-C like this:
#define STATUSBAR_HEIGHT [UIApplication sharedApplication].statusBarFrame.size....
2
votes
1
answer
3k
views
How do I access a preprocessor macro from code in Xcode using Swift?
How do I access a preprocessor macro in Xcode from Swift code for a string I've defined? Other stackoverflow posts show how to create the macros, but do not show me how to access them in code ...