• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Two basic questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: space bar event
  • Next by Date: Re: HTTP and FTP with cocoa
  • Previous by thread: Re: Two basic questions
  • Next by thread: Re: Two basic questions
  • Index(es):
    • Date
    • Thread