Reputation: 1
There is an error on the line that says totalSelection=[[NSString alloc] initWithFormat:dataView.text]; and the error says Format string is not literal, what does this mean?
- (void)viewDidLoad {
clientName= [[NSArray alloc] initWithObjects:@"Bob",@"Pete",@"Julie",@"Stacey",@"Eric", nil];
anteCedent= [[NSArray alloc] initWithObjects:@"Demand",@"Alone",@"Transition",@"FreePlay",@"Eating", nil];
problemBx = [[NSArray alloc] initWithObjects:@"Slap",@"Spit",@"Bite",@"Pinch",@"Threat", nil];
conSequence= [[NSArray alloc] initWithObjects:@"Attention",@"Ignored",@"Escape",@"Tangible",@"Redirected", nil];
[super viewDidLoad];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return componentCount;
}
//The layout of the picker view has been outlined and app can interpret the code
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component{
if (component==clientComponent){
return [clientName count];
}
if (component== bxComponent){
return [problemBx count];
}
if (component== antComponent){
return [anteCedent count];
}
if (component== conComponent){
return [conSequence count];
}
}
//Enables the app to correctly identify the number corresponding to each row
-(NSString *)pickerView:(UIPickerView*)pickerView titleForRow:(NSInteger)row forComponent: (NSInteger)component{
if (component==clientComponent){
return [clientName objectAtIndex:row];
}
if (component==bxComponent) {
return [problemBx objectAtIndex:row];
}
if (component==antComponent) {
return [anteCedent objectAtIndex:row];
}
if (component==conComponent){
return [conSequence objectAtIndex:row];
}
}
-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger) component{
NSString *Clientmessage;
NSString *BXmessage;
NSString *anteMessage;
NSString *conMessage;
if (component==clientComponent){
Clientmessage=[[NSString alloc] initWithFormat:@"%@",[clientName objectAtIndex:row]];
lblClient.text=Clientmessage;
}
if (component==bxComponent){
BXmessage=[[NSString alloc] initWithFormat:@"%@",[clientName objectAtIndex:row]];
lblBX.text=BXmessage;
}
if (component==antComponent){
anteMessage=[[NSString alloc] initWithFormat:@"%@",[clientName objectAtIndex:row]];
lblAnte.text=anteMessage;
}
if (component==conComponent){
conMessage=[[NSString alloc] initWithFormat:@"%@",[clientName objectAtIndex:row]];
lblBX.text=conMessage;
}
}
//Set the time and date and adding information
-(IBAction)EnterSelection:(id)sender;{
NSString *totalSelection;
NSDate *date1 = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSString *myDate = [dateFormatter stringFromDate:date1];
totalSelection=[[NSString alloc] initWithFormat:dataView.text];
totalSelection=[totalSelection stringByAppendingString:@"\n"];
totalSelection=[totalSelection stringByAppendingString:lblClient.text];
totalSelection=[totalSelection stringByAppendingString:@","];
totalSelection=[totalSelection stringByAppendingString:lblAnte.text];
totalSelection=[totalSelection stringByAppendingString:@","];
totalSelection=[totalSelection stringByAppendingString:lblBX.text];
totalSelection=[totalSelection stringByAppendingString:@","];
totalSelection=[totalSelection stringByAppendingString:lblCon.text];
totalSelection=[totalSelection stringByAppendingString:@","];
totalSelection=[totalSelection stringByAppendingString:myDate];
dataView.text=totalSelection;
}
//sets the code that will automatically enetered as the recipient of the email
-(void) send:(id) sender{
txtTo=@"[email protected]";
txtSubject=@"ABC Data";
[self sendEmailTo:txtTo withSubject:txtSubject withBody:[dataView text]];
}
//Organizes all email info and calls up mail function of iPhone
-(void) sendEmailTo: (NSString*)to withSubject:(NSString*)subject withBody:(NSString*)body {
txtTo=@"[email protected]";
txtSubject=@"ABC Data";
NSString *mailString= [NSString stringWithFormat:@"mailto:ff?to=%@&subject=%@&body=%@",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
}
// Do any additional setup after loading the view, typically from a nib.
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
Upvotes: 0
Views: 493
Reputation: 2495
Try this. initWithFormat:@"%@" will ignore any formatting.
//Set the time and date and adding information
-(IBAction)EnterSelection:(id)sender;{
NSString *totalSelection = [[NSString alloc] initWithFormat:@"%@", dataView.text];
NSDate *date1 = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSString *myDate = [dateFormatter stringFromDate:date1];
totalSelection=[totalSelection stringByAppendingString:@"\n"];
totalSelection=[totalSelection stringByAppendingString:lblClient.text];
totalSelection=[totalSelection stringByAppendingString:@","];
totalSelection=[totalSelection stringByAppendingString:lblAnte.text];
totalSelection=[totalSelection stringByAppendingString:@","];
totalSelection=[totalSelection stringByAppendingString:lblBX.text];
totalSelection=[totalSelection stringByAppendingString:@","];
totalSelection=[totalSelection stringByAppendingString:lblCon.text];
totalSelection=[totalSelection stringByAppendingString:@","];
totalSelection=[totalSelection stringByAppendingString:myDate];
dataView.text=totalSelection;
}
Upvotes: -1
Reputation: 385600
What if dataView.text
contains a %
? Then initWithFormat:
will interpret it as the beginning of a format specification and (possibly) try to look at arguments that you didn't pass in the message. You might crash or corrupt data. This type of bug is so common and serious that the compiler is programmed to detect the risk and warn you.
Since you don't want to use dataView.text
as a format string, don't pass it to initWithFormat:
. That line would be better written like this:
totalSelection = [dataView.text copy];
You could even rewrite the whole string-appending section like this:
totalSelection = [dataView.text stringByAppendingString:@"\n"];
NSString *fields = [@[
lblClient.text, lblAnte.text, lblBX.text, lblCon.text, myDate
] componentsJoinedByString:@","];
totalSelection = [totalSelection stringByAppendingString:fields];
Upvotes: 4