| Start |
|---|
| BOOL The Its behavior is straightforward and identical to the C language's. A The |
| SEL Selectors are used as method identifiers in Objective-C. In the example below, there are two selectors. Each pair of brackets corresponds to a message send. On the first line we send a message containing the Most of the time, message passing using the bracket syntax is sufficient, but occasionally you need to work with the selector itself. In these cases, the If the selector is available at compile time, you can use And if you need to find the selector at runtime, use NSSelectorFromString. When using NSSelectorFromString, make sure to wrap the selector name in a NSString. It is commonly used to check if a delegate implements an optional method. |
| id
This becomes relevant when retrieving objects from a collection. The return types of methods like It also means that a method or function parameter typed as When an object is typed as A message that the object does not actually respond to will still cause an exception at runtime, of course. Guarding against exception. The |
| IMP (implementation pointer) IMP is a C type referring to the implementation of a method, also known as an implementation pointer. It is a pointer to the start of a method implementation. Syntax: IMP is defined by: To access this IMP, the message “methodForSelector” can be used. Example 1: The method adressed by the IMP can be called by dereferencing the IMP. So these calls are equal: Example :2: Here, we call [NSObject methodForSelector which returns us a pointer to the C function that actually implements the method, which we can the subsequently call directly. |
| NSInteger and NSUInteger The NSInteger is just a typedef for either an int or a long depending on the architecture. The same goes for a NSUInteger which is a typedef for the unsigned variants. If you check the NSInteger you will see the following: The difference between an signed and an unsigned int or long is that a signed int or long can contain negative values. The range of the int is -2 147 483 648 to 2 147 483 647 while the unsigned int has a range of 0 to 4 294 967 295. The value is doubled because the first bit isn't used anymore to say the value is negative or not. For a long and NSInteger on 64-bit architectures, the range is much wider. Most methods Apple provides are returning an NS(U)Integer over the normal int. You'll get a warning if you try to cast it to a normal int because you will lose precision if you are running on a 64-bit architecture. Not that it would matter in most cases, but it is easier to use NS(U)Integer. For example, the count method on a array will return an NSUInteger. Just like a BOOL, the NS(U)Integer is a primitive datatype, so you sometimes need to wrap it in a NSNumber you can use the @ before the integer to cast it like above and retrieve it using the methods below. But to cast it to NSNumber, you could also use the following methods: Syntax
|
Read Article
https://develop.horje.com/learn/1434/reference