• 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: Inserting an (int) into an NSMutableArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inserting an (int) into an NSMutableArray


  • Subject: Re: Inserting an (int) into an NSMutableArray
  • From: Todd de Gruyl <email@hidden>
  • Date: Wed, 03 Aug 2005 15:07:24 -0400

On 8/3/05 14:32, Adam Raney wrote:
> I am showing my lack of knowledge of ObjC here, but I'm learning.
>
> I am trying to insert an int into an NSMutableArray, but getting an  error.

NSArray (and NSDictionary, and their mutable counterparts) hold objects.
 An int is not an object.  In order to insert an int (or any other
primitive type) into an NSMutable array, you need to put it into an
object that can hold the value, in this case it would be an NSNumber


> My int is an instance variable of my controller class. I am trying to
> add the int to an instance variable NSMutableArray of another class
> (already properly instantiated) through this process
>
> [myObject addItemToArray: myInt];

you can use this instead here:

  [myObject addItemToArray: [NSNumber numberWithInt: myInt]];

HTH,

--
Todd de Gruyl

Web:      <http://www.tdegruyl.com>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Inserting an (int) into an NSMutableArray (From: Adam Raney <email@hidden>)

  • Prev by Date: Re: Inserting an (int) into an NSMutableArray
  • Next by Date: Re: NSValueTransformer for selectedObjects controller key - bug?
  • Previous by thread: Re: Inserting an (int) into an NSMutableArray
  • Next by thread: NSValueTransformer for selectedObjects controller key - bug?
  • Index(es):
    • Date
    • Thread