3
CLLocationCoordinate2D coord = {latitude: 61.2180556, longitude: -149.9002778};
MKCoordinateSpan span = {latitudeDelta: 0.2, longitudeDelta: 0.2};
MKCoordinateRegion region = {coord, span};

What is this? Curly brackets?

Also shouldn't that be CLLocationCoordinate2D * coord

I saw them on http://www.iphonedevsdk.com/forum/tutorial-discussion/39374-mkmapview-tutorial-using-latitude-longitude.html

Totally strange.

user4951
  • 32,206
  • 53
  • 172
  • 282

1 Answers1

6

This is C99 “designated initializer” syntax for initializing structs. (It has nothing to do with the Objective-C concept of “designated initializers” for classes.)

Jens Ayton
  • 14,532
  • 3
  • 33
  • 47
  • I just realized I was wrong: this is the obsolete GCC “fieldname” extension. The equivalent C99 designated initializer syntax, which you should use instead, looks like this: `CLLocationCoordinate2D coord = { .latitude = 61.2180556, .longitude = -149.9002778 };` You can also use it in arrays: `int foo[5] = { [3] = 2 };`. If you use these forms, uninitialized fields are zeroed out. – Jens Ayton Jul 05 '11 at 12:08
  • This does not answer whether or not this is legal Objective-C. Are C99 constructs part of Objective-C? – Emile Cormier Oct 26 '11 at 21:13
  • 1
    Unlike C++, Objective-C is defined in terms of and layered on top of standard C. If you compile Objective-C code with the compiler set to accept C99, all C99 constructs are accepted. – Jens Ayton Oct 27 '11 at 21:12
  • Ah, that explains the "C Language Dialect" I see in the build settings. – Emile Cormier Oct 27 '11 at 21:43