Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6122493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:54:19+00:00 2026-05-23T15:54:19+00:00

Hi I am learning how to code in Objective-C. I want to store the

  • 0

Hi I am learning how to code in Objective-C. I want to store the values of the textfields in my view in an array:

NSArray* answers = [NSArray arrayWithObjects:fluidIntake.text, sleepQuality.text, sleepQuantity.text, mentalRecovery.text, 
                          physicalRecovery.text, pretrainingEnergy.text, muscleSoreness.text, generalFatigue.text, nil];

Is this possible? If not is there any cleaner way to store multiple textfield values without having to assign them to an NSString variable..

Update:

Here is the function in my view controller:

-(IBAction)postData:(id)sender{ 
    diary = [[PersonalDiary alloc]init];

    NSArray* answers = [NSArray arrayWithObjects:fluidIntake.text, sleepQuality.text, sleepQuantity.text, mentalRecovery.text, 
                          physicalRecovery.text, pretrainingEnergy.text, muscleSoreness.text, generalFatigue.text, nil];


    [diary post:answers to:  @"http://www.abcdefg.com/test.php"];   
}

It is triggered upon a button press. It should store the 8 values input into the textfields in an NSArray and pass this to a function in my Model class which which at the minute attempts to print the first element in the array (i.e. the first textfield value):

-(void) post:(NSArray*) ans to:(NSString*) link{
    NSLog(@"%@", ans[0]); 
}

But it doesn’t, it just prints : PersonalDiary[37114:207] __NSArrayI

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:54:20+00:00Added an answer on May 23, 2026 at 3:54 pm

    You are incorrectly indexing the array in this method and using the wrong kind of string.

    -(void) post:(NSArray*) ans to:(NSString*) link{
        NSString* a = "Hello";
        NSLog(@"%s%d", a, ans[0]); 
    }
    

    ans[0] will print the pointer address of your NSArray and not access your elements. To access your array you need to use objectAtIndex:. All NSString literals need to be prefixed with @. And when you print any kind of Objective-C object use %@ format. Also it is not safe to access objects of the array without checking the count first.

    -(void) post:(NSArray*) ans to:(NSString*) link{
        NSString* a = @"Hello";
        NSLog(@"%@ %@", a, [ans objectAtIndex:0]); 
        //Or print entire array
        NSLog(@"%@", ans);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just learning objective-C, and have a book with code like this: NSArray
I am just learning objective-c but can't figure out whats wrong with my code
I've been learning Objective C lately, and I came across some code for using
I'm in the process of learning Objective-c but would like to run code snippets
I'm learning Objective-C and just trying out some sample code. I am getting the
I recently started learning Objective-C 2.0, with a book, and I want to know
I'm just learning how to code for the iPhone using Objective-C, and I don't
Learning Objective-C and reading sample code, I notice that objects are usually created using
I am learning Objective C . I was given a code to fix that
What is machine learning ? What does machine learning code do ? When we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.