• 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: Objective C array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective C array


  • Subject: Re: Objective C array
  • From: Sherm Pendley <email@hidden>
  • Date: Fri, 31 May 2002 16:56:36 -0400

On Friday, May 31, 2002, at 04:29 PM, Eric Conrad wrote:

Hello,
I am new to Objective-C I tried getting help on this through the C gurus on IRC, but they couldn't help either. What I want to do is read an array with a simple for loop. Basically I'm making a simple GPA calculating program. Here is my code:

- (IBAction)calculate:(id)sender
{
float classCredits[10];
float classGrades[10];
float totalCredits, totalGrades, gpaFinal;
int i;

for(i=0; i<10; i++)
{
classCredits[i] = [classCredit? floatValue]; <--------
classGrades[i] = [classGrade? floatValue]; <--------

}

One thing that comes to mind is tags. You can assign a unique integer tag value to each classCredit? field in IB, and use NSView's viewWithTag: method to retrieve a reference to the correct one each time through the loop. For example, assuming that "classWindow" is an outlet connected to the window containing the fields:

- (IBAction)calculate:(id)sender
{
float classCredits[10];
float classGrades[10];
float totalCredits, totalGrades, gpaFinal;
int i;

NSView *classTopView;

classTopView = [classWindow contentView];

for(i=0; i<10; i++)
{
classCredits[i] = [[classTopView viewWithTag: 100+i] floatValue];
classGrades[i] = [[classTopView viewWithTag: 200+i] floatValue];
}
}

The above also assumes that tags 100-109 have been assigned to classCredit? fields, and 200-209 to classGrade? fields.

I typed this directly into email, without compiling it, so there may be typos.

Hope this helps!

sherm--

Never put off until tomorrow what you can do today. There might be a law against it by that time.
_______________________________________________
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.
References: 
 >Objective C array (From: Eric Conrad <email@hidden>)

  • Prev by Date: Re: Getting font info
  • Next by Date: Re: Objective C array
  • Previous by thread: Re: Objective C array
  • Next by thread: Re: Objective C array
  • Index(es):
    • Date
    • Thread