Bestive-C Best practice for writing a simple method?

In the next feature, which is the best practice?

  • To send an auto-implemented object and force the caller to save it?

  • or send the selected object and make it the caller?


- (NSString *) convertDataToString: (NSData *) myData
{
     // just an example, method might not exist
     NSString * str = [[NSString alloc] initWithData: myData];
     return str;
     return [str autoRelease];
}
+3
source share
6 answers

, - - . , . , , .

:

. , .

 – (NSArray *)sprockets {

    NSArray *array = [[NSArray alloc] initWithObjects:mainSprocket,
                               auxiliarySprocket, nil];
    return array;
}

, , . , . . , , , . , , .

+3

@Chuck, -convertDataToString , . . "", "alloc" "new" , , . "" "" "alloc", .

Objective-C , . , .

+7

. [alloc, new, copy], .

+2

, , . , .

+1

. , , , . . , , .

0

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


All Articles