How to handle an array of pointers in Objective-C

I understood the answer to this question, but I could not find a solution here, so I am sending it to posterity.

So, in Objective-C, how do you create an object from a pointer to store it in objective-c collections (NSArray, NSDictionary, NSSet, etc.) without returning to regular C?

+3
source share
2 answers
NSValue *pointerObject = [NSValue valueWithPointer:aPointer];

This will wrap the pointer in NSValue. To return it later, use the NSValue instance method (pointerValue :)

+8
source

, , / , .

NSValue, .

- :

@interface FooPtr:NSObject
{
    void *foo;
}

+ fooPtrWithFoo: (void *) aFoo;

.... methods here ...
@end

(void *), : " ". - #define FOOPTR(foo) ((Foo *) foo) FOOPTR(foo)->bar; .

Objective-C . - . / foo ..

+1

Source: https://habr.com/ru/post/1745833/


All Articles