1 Reply
      Latest reply: Nov 15, 2016 1:39 AM by eskimo RSS
      imneo Level 1 Level 1 (0 points)

        With the new template feature, I can now write code like this:

        NSArray<NSString*>* a = [NSArray arrayWithObjects:@1, [NSDate date], nil];
        NSLog(@"%@", a);
        

        Now the question for me is that it seems the <template> syntax is only about annotation. The compiler does not even issue a warning about the above code; neither does the runtime crash on the NSLog line. That's quite confusing.

         

        I could not find this new syntax in the official "Programming With Objective-C" book. Can someone direct me to some useful resources? Thanks.

        • Re: Objective-C template syntax question
          eskimo Apple Staff Apple Staff (6,685 points)

          Now the question for me is that it seems the … syntax is only about annotation.

          Correct.  Objective-C retains its dynamic nature at runtime; this syntax can help with compile-time error checking, and definitely helps with Swift integration, but it does not make Objective-C a statically typed language.

          Anyway, the droid you’re looking for here is “lightweight generics”.  If you search the ’net for that term, you’ll find lots of info about it.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"