Does ARC put my reference object (ODQuery)?

I am a little new to cocoa and took advantage of the apple example here: Open the catalog programming guide

In this example, they capture the ODQuery object with persistence, this is no longer permitted, and I cannot find another way to tell the compiler to leave my link alone. As I understand it, alloc does not do this either.

The link seems to be lost when ODQuery is passed to NSRunLoop, which in turn must pass it to the query: foundResults: error.

Here's the code (it should look for a group with the same name as my computer):

NSString *computer = [[NSHost currentHost] localizedName]; NSError *err; ODQuery *aQuery = [[ODQuery alloc] initWithNode:adNode forRecordTypes:kODRecordTypeGroups attribute:kODAttributeTypeRecordName matchType:kODMatchBeginsWith queryValues:computer returnAttributes:kODAttributeTypeStandardOnly maximumResults:0 error:&err]; [aQuery setDelegate:self]; [aQuery scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 

I assign adNode and session as private variables and assign them in the init method:

 NSError *err; NSString *nodeName = @"/Active Directory/GU/gu.gu.se"; theSession = [ODSession defaultSession]; adNode = [ODNode nodeWithSession:theSession name:nodeName error:&err]; NSLog(@"Error from initWorker: %@", [err localizedDescription]); 

I implemented the ODQueryDelegate protocol by overriding the method request: foundResults: error. When it is called from NSRunLoop, the program crashes due to pointer errors.

 - (void)query:(ODQuery *)inQuery foundResults:(NSArray *)inResults error:(NSError *)inError 

Hope someone can help.

+4
source share

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


All Articles