Re: [Objectivelib-discussion] Looks like I might get to open the bidding :-)
Brought to you by:
will_mason
From: Daniel R. <ult...@gm...> - 2005-07-22 19:49:22
|
On Jul 22, 2005, at 1:48 PM, Will Mason wrote: > Hi, Rod, > How could we not be kind in responding to the first actual question > posted to the list. To answer your question, you can't put simple data > types in containers, just objects. Fortunately, Cocoa and GNUstep > provide a convenient wrapper for primitive data types, NSNumber. You > can do this: > > OLVector* v = [OLVector vector]; > [v pushBack: [NSNumber numberWithDouble: 3.14]]; > > Check the docs for NSNumber to see how it works. Let me know if you > need anything else, > Will > NSNumber presents one of those revealing aspects of the Objective-C philosophy. Rather than templates, which can get troublesome, it's nothing to create a class that can work with any object, unfortunately leaving out basic data types. Additionally, if you're ever interested in wrapping other forms of non-object data (such as structs or pointers), take a look at NSNumber's super class, NSValue. It's incredibly useful and isn't advertised enough. -Daniel |