All Questions

Tagged with
Filter by
Sorted by
Tagged with
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 ...
Dharmesh Kheni's user avatar
77 votes
5 answers
108k views

How to use a Objective-C #define from Swift

I am migrating a UIViewController class to train a bit with Swift. I am successfully using Objective-C code via the bridging header but I have the need of importing a constants file that contains #...
atxe's user avatar
  • 5,049
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 ...
Geri Borbás's user avatar
  • 16.2k
36 votes
5 answers
54k views

Implicit declaration of function - C99

I am currently using Xcode 4, and in my .pch file I have this macro: #define localize(s) NSLocalizedString((s), nil). When I try to use this macro in some .m file, I receive this warning: Implicit ...
Misa's user avatar
  • 889
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 ...
ankushg's user avatar
  • 1,632
20 votes
4 answers
7k views

@"" string type literals for NSNumber

I love the shorthand handling of string literals in Objective C with the @"string" notation. Is there any way to get similar behavior with NSNumbers? I deal with numbers more and it's so tedious ...
rob5408's user avatar
  • 2,972
20 votes
8 answers
16k views

How to make a macro that can take a string?

I'm trying to do something really trivial: A macro that takes an string and prints that to NSLog. Like this: #define PRINTTHIS(text) \ NSLog(@"text"); However, when I try to pass a string to ...
Another Registered User's user avatar
18 votes
1 answer
5k views

Swift alternative for #pragma clang diagnostic

Problem I recently encountered a warning in a third party utility (WEPopover) in this piece of code: _effectivePopoverContentSize = _contentViewController.contentSizeForViewInPopover; This was ...
Tommie C.'s user avatar
  • 13.1k
16 votes
2 answers
1k views

Meaning of Objective-C macros prefixed with an at (@) symbol

The ReactiveCocoa framework makes use of weakify and strongify macros, both of which are preceded by an '@' symbol. Here's an example (From this file). - (RACSignal *)rac_textSignal { @...
ColinE's user avatar
  • 69.5k
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....
Karthick's user avatar
  • 382
15 votes
4 answers
20k views

What does "macro" mean in Objective-C?

I am new to iOS development and I just want to know the meaning of macro in Objective-C? I have found that "macro" is used with #define but still do not get its meaning. http://www.saturngod.net/ios-...
sudeveloepr's user avatar
14 votes
2 answers
7k views

Accessing the value of a Preprocessor Macro definition

If I add a macro "FOO=bar" under GCC_PREPROCESSOR_DEFINITIONS (or Preprocessor Macros if you use XCode"), what would be the best way to access the value of "FOO"? Currently, I use the clumsy: #...
Adriaan Tijsseling's user avatar
11 votes
1 answer
9k views

Objective C - Defining macro to call a method?

I want to define a macro to call the following, Is this possible? I also want it to accept format string. - (void)logString:(NSString *)string withLogLogLevel:(LogLevel)logLevel { // Sav log to ...
aryaxt's user avatar
  • 77k
10 votes
1 answer
4k views

Where is the DEBUG macro defined?

When I run code such as the following: - (void)viewDidLoad { #ifdef DEBUG NSLog(@"debug"); #else NSLog(@"here"); #endif [super viewDidLoad]; } I see "debug" printed in the log, but I ...
itenyh's user avatar
  • 1,929
10 votes
1 answer
6k views

How to suppress "macro redefined" warning in Objective-C

I need to redefine a macro in my project and have a compile warning. I've tried #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wall" #define SomeMacroToRedefine MyMacro #pragma ...
Maxim Lavrov's user avatar
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) ...
lvp's user avatar
  • 2,088
9 votes
5 answers
9k views

How can I write a 'clamp' / 'clip' / 'bound' macro for returning a value in a given range?

I often find myself writing something like int computedValue = ...; return MAX(0, MIN(5, computedValue)); I would like to be able to write this as a single one-line macro. It must be free of side ...
hfossli's user avatar
  • 22.8k
9 votes
1 answer
5k views

Objective C MAX macro bug

I'm seeing strange behavior with the MAX macro in Objective C. Specifically, I have this code in my main function: NSArray* array = [NSArray array]; NSLog(@"[array count] - 1 = %d", [array count] - ...
Adam Crume's user avatar
  • 15.7k
9 votes
2 answers
1k views

How to require ARC in a class?

I have an app with both ARC code and non-ARC code. The compiler will catch when I try to compile non-ARC code as ARC. How do I cause a compile time error/notice when my ARC code is erroneously ...
adonoho's user avatar
  • 4,339
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: ...
Ben Stock's user avatar
  • 1,996
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.
sairam's user avatar
  • 299
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 ...
John Lane's user avatar
  • 1,112
7 votes
2 answers
6k views

Objective-C Macro Redefinition

I am currently using three servers (deploy, live_testing, and local). I am using macros to define a serie of domain locations: #define __LIVE_TESTING // Here I chose what domain to use #ifdef ...
r1d3h4rd's user avatar
  • 141
7 votes
1 answer
5k views

XCode Preprocessor Macro for Configuration?

I want my XCode Objective-C project to be able to detect which configuration it is being built with. How can I achieve this?
JP Richardson's user avatar
7 votes
1 answer
6k views

Is there a way to check how a macro "expands" in C or Objective-C

A macro is a preprocessor right. Sometimes we set things right sometimes we don't. Wouldn't it be nice to once in a while expand the macro and see how it works?
user4951's user avatar
  • 32.6k
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(...
AAV's user avatar
  • 3,805
7 votes
3 answers
6k views

Conditional macro expansion

Heads up: This is a weird question. I've got some really useful macros that I like to use to simplify some logging. For example I can do Log(@"My message with arguments: %@, %@, %@", @"arg1", @"arg2"...
Dave DeLong's user avatar
7 votes
3 answers
365 views

Using C macros to create C-style code which maps to Objective-C message calls?

I'm sure I'll get 20 people saying "why would you want to do that anyways"... but, I'm going to ask my question none-the-less because it's somewhat academic in nature. I'd like to use C macros to ...
Steve's user avatar
  • 31.4k
7 votes
1 answer
429 views

How can I use commercial at sign in Objective-C macro?

How can I use commercial at sign in Objective-C macro? I know it is not recommended, but seems it is possible somehow? Since libextobjc provides @weakify, @strongify, etc...
Nik's user avatar
  • 9,210
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 ...
Pratik Bhiyani's user avatar
7 votes
2 answers
3k views

How to expand a MACRO into NSString without using any string concatenation at runtime?

I defined a macro MYMACRO. Note: the value is not a valid NSString. #define MYMACRO is The macro is used inside the declaration of a NSString @"This MYMACRO fun" However, the preprocessor does not ...
David Andreoletti's user avatar
6 votes
4 answers
9k views

#define: why uppercase?

When defining a macro (e.g. #define BALL). Why do people use uppercase letters? I can write something like #define ball. It is not in uppercase, but it works.
nicael's user avatar
  • 18.7k
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 ...
zumzum's user avatar
  • 19k
6 votes
3 answers
5k views

How to detect C++ compiler with macro in Xcode?

I'm mixing Objective-C (*.m) and Objective-C++ (*.mm) source files in an iOS project. When I import a C++ header file in a *.m file how can I exclude the C++-specific code in the header file? I want ...
Felix's user avatar
  • 35.4k
6 votes
2 answers
6k views

Objective-C: Where to define macros to be available everywhere?

I have an iOS application which uses in many view controllers, the same strings, numbers, etc. So I think it would be much better to define these constants in one file and use it in all the view ...
Tim's user avatar
  • 13.2k
6 votes
3 answers
2k views

Objective-C Safe Casting Macro

I've written a macro in Objective-C to perform a safe cast. Here's what it looks like so far: #define SAFE_CAST(OBJECT, TYPE) ([OBJECT isKindOfClass:[TYPE class]] ? (TYPE *) OBJECT: nil) This works ...
LandonSchropp's user avatar
6 votes
2 answers
2k views

Global Variables for Class Methods

Background In Cocoa, Apple frequently makes use of the following paradigm: [NSApplication sharedApplication] [NSNotificationCenter defaultNotificationCenter] [NSGraphicsContext currentContext] [...
Patrick Perini's user avatar
6 votes
4 answers
2k views

Objective-C: Function-Like Macro Vs. Method

In Objective-C, when do you recommend using function-like macros over class or instance methods?
ma11hew28's user avatar
  • 124k
6 votes
2 answers
3k views

NSImageView rounded corners + stroke

I have subclasses NSImageView and i want to draw a border around with rounded corners. It works but i need to clip off the image corners as well. Please see my screenshot: I have created this code ...
Rasmus Styrk's user avatar
  • 1,336
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 ...
Chuck Krutsinger's user avatar
6 votes
3 answers
1k views

Asserting object class in Objective C

I often find myself asserting that an object "isKindOfClass" of some class in Objective-C. I do it like this: NSAssert([obj isKindOfClass:[AClass class]], @"%@ should be kind of class %@", obj, [[...
jbat100's user avatar
  • 16.8k
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 ...
optz's user avatar
  • 471
5 votes
7 answers
20k views

Is Macro Better Than UIColor for Setting RGB Color?

I have this macro in my header file: #define UIColorFromRGB(rgbValue) \ [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ green:((float)((rgbValue & ...
Rahul Vyas's user avatar
  • 28.5k
5 votes
5 answers
9k views

ABS(A) and abs(int)

I am baffled in the difference of this two in xcode, ABS(A) and abs(int). Cant seem to find ay explanation online as well. Which should I use? I am actually working on an accelerometer. Using ABS(A) ...
Hexark's user avatar
  • 413
5 votes
2 answers
3k views

Macro for NSLocalizedString

All my calls of NSLocalizedString have nil as second param, because i don't use any comments. But i hate to repeat myself. Now i'm asking myself if it's ok to define a macro like LSSTRING(str) that ...
peko's user avatar
  • 11.3k
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]...
divillysausages's user avatar
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 { #...
Peter Lapisu's user avatar
  • 20.5k
5 votes
2 answers
3k views

How to make NSString macro?

How to make a macro that represents a constant NSString value? I'm getting "Multi-character character constant" and "Character constant too long for its type" warnings when defining in Xcode 4: #...
Centurion's user avatar
  • 14.2k
5 votes
0 answers
866 views

Disable NSLog for CocoaPods

I am using several CocoaPods in my project. Some of them are outputting strings to the console via NSLog(). How can I disable all logging from CocoaPods? Also, is there a way to do so while still ...
Senseful's user avatar
  • 89.2k
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?
cschuff's user avatar
  • 5,522

1
2 3 4 5
7