Re: Two basic questions
Re: Two basic questions
- Subject: Re: Two basic questions
- From: email@hidden
- Date: Thu, 28 Feb 2002 11:51:28 -0800
Acks, oops. Sorry, I meant; "returned from a function". Sorry
about that all.
In Objective-C there are no functions. Your example is a method.
I.e., you can send a [myObject myFunc]; but you can't call
myFunc; or myFunc();
Sure there are. Foundation and AppKit have lots of functions in their
API, in fact. Functions are very much a part of Obj-C.
- (NSString *)myFunc
{
NSMutaleString *string = [NSMutableString stringWithCapacity:0];
[string appendString:@"test"];
// You should convert to the correct type as well as take care of
// deallocation:
return [[string copy] autorelease];
return string;
}
This should not be necessary, and reduces the efficiency of the code.
There is nothing wrong with returning mutable objects in place of
immutable ones. The only possible issue is if your code was also
keeping a reference to the mutable string in question, and might change
it later (thereby changing the value of the string you already returned
to some caller from your API). As long as you can be sure, as you can
in this case, that nobody will change the value of the string "out from
under" the caller of your API, it is fine to do.
Ben Haller
Stick Software
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.