Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-23-2011, 03:46 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 2
kohdurr is on a distinguished road
Default Taking input into an array

Hello, this is my first post. I started off learning C++ then moved to Objective-C for iOS development. I have a pretty n00b question. Basically, I want to accept a users input and then store that input as part of an array (NSMutableArray). What would be the best way to go about this?

The code below is what I am currently working on to familiarize myself with Obj-c. It is a very basic program, sorry for the messy code.

The issue I am talking about happens at the very end of the code, the rest is just me having fun with conditional statements.

Code:
#import <stdio.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSString.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSEnumerator.h>
#import "Fraction.h"
#import "Age.h"
#import "Color.h"

int main ( int argc, const char *argv[] ) {
    //create a new instance
    Fraction *frac = [[Fraction alloc] init];
    Fraction *frac2 = [[Fraction alloc] init];
    
    //set the values
    [frac setNumerator: 1];
    [frac setDenominator: 5];
    [frac2 setNumerator: 7];
    [frac2 setDenominator: 9];
    
    //print it
    printf( "The fraction is: " );
    [frac print];
    printf( "\n" );
    [frac2 print];
    printf( "\n" );
    
    //print conditional statement
    if ( [frac denominator] == 5 ) 
    {
        printf( "Wowza\n" );
    }
    else 
    {
        printf( "WRONG!!" );
    }
    
    //free memory
    [frac dealloc];
    [frac2 dealloc];
    
    //set the age value
    Age *yourAge = [[Age alloc] init];
    int b;
    
    //print statement
    printf( "What is your age?\n" );
    scanf ( "%i", &b );
    [yourAge setAgeOfPerson:b];
    [yourAge printAge];
    [yourAge dealloc];
    
    //array
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    Color *difColor = [[Color alloc] init];
    NSMutableArray *newColors = [NSMutableArray array];
    newColors = [NSMutableArray arrayWithObjects:@"green", nil];
    NSString *yourColor;

    printf( "What is your favorite color?\n" );
    
    scanf( "%i", yourColor );
    
    [newColors addObject: &yourColor];
    
    
    NSLog( @"%@", newColors );
    
    //free memory
    [difColor dealloc];
    [newColors release];
    
    //drain pool
    [pool release];
    return 0;
}
kohdurr is offline   Reply With Quote
Old 06-26-2011, 09:12 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Never ever ever ever ever call dealloc on an object directly. Call release and if the retain count is 0, it's dealloc method will be called.
Domele is offline   Reply With Quote
Old 07-08-2011, 02:49 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 2
kohdurr is on a distinguished road
Default

Thanks for the advice, I didn't know that was improper.

Any suggestions on storing user input into an array? It's a simple enough concept but I can't seem to get it to work.
kohdurr is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 474
16 members and 458 guests
7twenty7, AlanFloyd, AppsBlogger, David-T, HemiMG, iAppDeveloper, imac74, Jaxen66, lovoyl, Music Man, mutantskin, Paul Slocum, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:15 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0