Lines Matching +full:objective +full:- +full:c
2 Objective-C Literals
10 scalar literal expressions; *Collection Literals* provide a short-hand
12 way to use subscripting with Objective-C objects. Users of Apple
14 Compiler 4.0. Users of open-source LLVM.org compiler releases can use
17 These language additions simplify common Objective-C programming
30 ``double``), and boolean values (``BOOL``, C++ ``bool``). Scalar values
33 In Objective-C, any character, numeric or boolean literal prefixed with
35 object initialized with that value. C's type suffixes may be used to
39 --------
43 .. code-block:: objc
70 ----------
76 .. code-block:: objc
79 #define INT_MIN (-2147483647-1) /* min value for an int */
96 .. code-block:: objc
110 Objective-C++ also supports ``@true`` and ``@false`` expressions, which
116 Objective-C provides a new syntax for boxing C expressions:
118 .. code-block:: objc
122 Expressions of scalar (numeric, enumerated, BOOL), C string pointer
123 and some C structures (via NSValue) are supported:
125 .. code-block:: objc
128 NSNumber *smallestInt = @(-INT_MAX - 1); // [NSNumber numberWithInt:(-INT_MAX - 1)]
146 -----------
150 boxed literals (this avoids conflicts with future ``'@'``-prefixed
151 Objective-C keywords). Instead, an enum value must be placed inside a
156 .. code-block:: objc
166 - (AVAudioRecorder *)recordToFile:(NSURL *)fileURL {
173 :ref:`fixed underlying type <objc-fixed-enum>` as in:
175 .. code-block:: objc
185 be a :ref:`fixed underlying type <objc-fixed-enum>`
186 or a compiler-defined integer type capable of representing the values of
189 .. code-block:: objc
195 Boxed C Strings
196 ---------------
198 A C string literal prefixed by the ``'@'`` token denotes an ``NSString``
203 equivalent character data, which is assumed to be '\\0'-terminated and
204 UTF-8 encoded. The following example converts C-style command line
207 .. code-block:: objc
212 while (--argc) {
214 if (strncmp(arg, "--", 2) == 0) {
215 options[@(arg + 2)] = @(*++argv); // --key value
221 As with all C pointers, character pointer expressions can involve
227 Boxed C Structures
228 ------------------
231 It said that C structures can be used, the only requirement is:
233 To support older version of frameworks and/or third-party libraries
236 .. code-block:: objc
266 Objective-C now supports a new expression syntax for creating immutable
270 --------
274 .. code-block:: objc
278 This creates an ``NSArray`` with 3 elements. The comma-separated
279 sub-expressions of an array literal can be any Objective-C object
284 .. code-block:: objc
293 sub-expressions of a dictionary literal must be Objective-C object
294 pointer typed, as in array literals. Key sub-expressions must be of an
295 Objective-C object pointer type that implements the
299 ----------
308 objects are non-``nil``. The variadic form,
320 Objective-C object pointer values can now be used with C's subscripting
324 --------
329 .. code-block:: objc
346 --------------------
348 Objective-C supports two kinds of subscript expressions: *array-style*
349 subscript expressions use integer typed subscripts; *dictionary-style*
350 subscript expressions use Objective-C object pointer typed subscripts.
358 Array-Style Subscripting
366 .. code-block:: objc
373 .. code-block:: objc
379 .. code-block:: objc
385 .. code-block:: objc
389 These message sends are then type-checked and performed just like
392 some Objective-C object pointer type. The method used for
394 having some Objective-C pointer type and its second argument having
399 uses for type-checking. For an instance of ``NSArray``, reading an
410 to type-check; moreover, its subclass ``NSMutableArray`` declares
413 Dictionary-Style Subscripting
416 When the subscript operand has an Objective-C object pointer type, the
419 expression reads an element using an Objective-C object pointer
422 .. code-block:: objc
429 .. code-block:: objc
433 When an expression writes an element using an Objective-C object pointer
436 .. code-block:: objc
442 .. code-block:: objc
446 The behavior of ``setObject:forKeyedSubscript:`` is class-specific; but
452 ----------
454 An Objective-C subscript expression occurs when the base operand of the
455 C subscript operator has an Objective-C object pointer type. Since this
457 expressions are only supported under the modern Objective-C runtime,
460 Currently, only subscripts of integral or Objective-C object pointer
461 type are supported. In C++, a class type can be used if it has a single
462 conversion function to an integral or Objective-C pointer type, in which
464 Otherwise, the expression is ill-formed.
466 An Objective-C object subscript expression is always an l-value. If the
467 expression appears on the left-hand side of a simple assignment operator
469 appears on the left-hand side of a compound assignment operator (e.g.
470 +=), the program is ill-formed, because the result of reading an element
471 is always an Objective-C object pointer and no binary operators are
474 address of a subscript expression, or (in C++) to bind a reference to
477 Programs can use object subscripting with Objective-C object pointers of
487 be newly-allocated. As such, the result of performing direct comparisons
489 ``<=``, ``>``, or ``>=``) is not well-defined. This is usually a simple
493 This caveat applies to compile-time string literals as well.
503 To support the new syntax described above, the Objective-C
504 ``@``-expression grammar has the following new productions:
508 …objc-at-expression : '@' (string-literal | encode-literal | selector-literal | protocol-literal | …
511 object-literal : ('+' | '-')? numeric-constant
512 | character-constant
513 | boolean-constant
514 | array-literal
515 | dictionary-literal
518 boolean-constant : '__objc_yes' | '__objc_no' | 'true' | 'false' /* boolean keywords. */
521 array-literal : '[' assignment-expression-list ']'
524 assignment-expression-list : assignment-expression (',' assignment-expression-list)?
528 dictionary-literal : '{' key-value-list '}'
531 key-value-list : key-value-pair (',' key-value-list)?
535 key-value-pair : assignment-expression ':' assignment-expression
538 Note: ``@true`` and ``@false`` are only supported in Objective-C++.
546 .. code-block:: objc
550 NSArray *elements = @[ @"H", @"He", @"O", @"C" ];
553 id objects[] = { @"H", @"He", @"O", @"C" };
559 … NSDictionary *masses = @{ @"H" : @1.0078, @"He" : @4.0026, @"O" : @15.9990, @"C" : @12.0096 };
562 id keys[] = { @"H", @"He", @"O", @"C" };