0

The NSDictionary class allows me to initialise it like this:

NSDictionary* attributes =
@{
  NSFontAttributeName: font
};

What is this construction method called, and how I can implement it in my own class? I want to have a class with properties that have default values, and I'd like to only set the ones I need during construction (in C++ I would have done this with default parameter values, but Objective-C does not have that), so this seemed like a legitimate approach. Or is this something NSDictionary specific?

jscs
  • 63,694
  • 13
  • 151
  • 195
Rudolfs Bundulis
  • 11,636
  • 6
  • 33
  • 71
  • Can't you set the default values of your properties in the class `init`? Or maybe create multiple `init`'s for the different cases? – VitorMM Jul 18 '17 at 00:51
  • Of course I can, simply I would like to avoid writing any init methods at all (somewhat similar like the C# property initializer ctor syntax), but if this extension is not for that then well - no luck. – Rudolfs Bundulis Jul 18 '17 at 08:13

0 Answers0