How to define array in Macros in Objective-c?
Asked Answered
C

2

8

Is there any possibility to define arrays in macro in objective-c.

Copyedit answered 12/9, 2012 at 7:43 Comment(1)
See this.Geometric
A
10

You can also just do:

#define MY_ARRAY @[ @"foo", @"bar" ]
Aghast answered 7/3, 2014 at 22:15 Comment(1)
can u tell me how to declare array of long value in #define?Bicameral
R
16

Yes, you can define arrays in macros. e.g

#define MY_ARRAY [NSMutableArray arrayWithObjects:someObj1, someObj2, nil]
Renter answered 12/9, 2012 at 7:51 Comment(3)
@Renter Can you pls tell how to access or retrieve this.Blumenfeld
It would be the same as you would use an NSMutableArray object, e.g NSLog(@"Object at index 0 is %@",[MY_ARRAY objectAtIndex:0]);Renter
how to add aobject ?like :[ MY_ARRAY addobject:@"obj"];Castrato
A
10

You can also just do:

#define MY_ARRAY @[ @"foo", @"bar" ]
Aghast answered 7/3, 2014 at 22:15 Comment(1)
can u tell me how to declare array of long value in #define?Bicameral

© 2022 - 2024 — McMap. All rights reserved.