I am creating a program in the iOS SDK in which there is a group of buttons. When a button is clicked, its title is added to an array, and the array is displayed in an assigned label.
When I try to create delete and clear buttons, error messages show up. They show up in the function_builder = function_builder.removeLastObject; and function_builder = function_builder.removeAllObjects; lines of the .m file. The error messages are the same: Assigning to ‘NSMutableArray *_strong’ from incompatible type ‘void’. How do I fix this?
Thank you for any and all help
Here is the .h file:
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
@property (nonatomic,strong) IBOutlet UILabel *equation_field;
@property (nonatomic) NSMutableArray *function_builder;//declare array//
@property(nonatomic, readonly, retain) NSString *currentTitle;//declare button titles//
@end
And here is the .m file:
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize equation_field;
@synthesize currentTitle;
@synthesize function_builder;
NSMutableArray *function_builder;//create the array name//
- (IBAction)functionButtonPress:(UIButton *)sender {//code for all buttons except delete and clear//
[function_builder addObject: sender.currentTitle];//when button is pressed, its title is added to the array//
self.equation_field.text = function_builder.description;//the contents of the array appear in the assigned label//
}
- (IBAction)delete:(UIButton *)sender {//create delete button//
function_builder = function_builder.removeLastObject; //ERROR OCCURRING HERE: Assigning to 'NSMutableArray *_strong' from incompatible type 'void'//
}
- (IBAction)clear:(UIButton *)sender{//create clear button//
function_builder = function_builder.removeAllObjects;//ERROR OCCURRING HERE: Assigning to 'NSMutableArray *_strong' from incompatible type 'void'//
}
- (void)viewDidLoad {
function_builder = [[NSMutableArray alloc] init];//initialize array//
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
Many errors there..
You’ve assigned the results of this methods (void*) to function_builder which is of kind NSMutableArray. That makes no sense.
In order to manipulate an object, just send a message to it:
For the other thing:
This will create a string with all objects in array separated by “, ” =>
A, B, C, D