0
-(NSMutableArray *) botanicalPlant {
if (_botanicalPlant == nil) {
    _botanicalPlant = [[NSMutableArray alloc] initWithObjects:@"Abelia", nil];
   }
return _botanicalPlant;
}

- (void)viewDidLoad
{
   [super viewDidLoad];

self.botanicalPlantName = [[BotanicalPlant alloc] init];
self.botanicalPlantNameLabel.text = []
}

I know this may be a simple question but Im stuck on this one. I have an array in NSObject of Botanical I just don't know how to call it in the viewDidLoad method for it to show up in my main view controller. I don't know what to put in the brackets to assign it to the text of the label.

2 Answers 2

2

You haven't shown enough code to answer your question for sure. But if botanicalPlant is a mutable array property on the BotanicalPlant class, then you could do something like:

BotanicalPlant *myBotanicalPlant = [[BotanicalPlant alloc] init];
NSMutableArray *namesArray = myBotanicalPlant.botanicalPlant;
self.botanicalPlantNameLabel.text = [namesArray firstObject];
Sign up to request clarification or add additional context in comments.

Comments

0

Try This:

In your viewDidLoad method

 NSMutableArray *arrayFromBotanicalMethod = [self botanicalPlant];

// Then set the text label from your new array that you created

self.botanicalPlantNameLabel.text = [arrayFromBotanicalMethod objectAtIndex:0];

This code is based on the limited information you provided. You basically create another array that will hold the returned array from your botanicalPlant method. Then you use the objectAtIndex message on the new array to get the text for the label.

Hope it helps.

1 Comment

One minor correction: "You basically create another array that will hold the returned array" is incorrect. "You create a reference to the returned array" would be correct. They are two different pointers to the same array; no copies are made.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.