Format String is not a literal string (potentially insecure) warning [duplicate] - objective-c

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Warning: “format not a string literal and no format arguments”
I have the following line of code that is in my app that a Developer worked on. I am learning the basics of Objective C and as I was updating the App to be iPhone 5 compatible, I see the following warning (I did not change his code) Format String is not a literal string (potentially insecure). The code is as follows;
self.progressHud.labelText = [NSString stringWithFormat:message];
I don't know exactly what this means and don't want to upload anything that can either be a security issue or get rejected by Apple. Any and all help is appreciated from you all.

Use the following Lines:
self.progressHud.labelText = [NSString stringWithFormat:#"%#", message];
In objective C, this line get the values from any format such as int,float etc to display the Label. because UILabel and IBOutlet Elements only display the NSString values.
However, if you don't need to create a string with multiple variables, it would be more efficient to simply use:
self.progressHud.labelText = message;

Related

Preprocessor macro taking NSString stringWithFormat fails due to comma [duplicate]

This question already has answers here:
Comma in C/C++ macro
(8 answers)
Closed 5 years ago.
Assuming I have a macro like this
#define A(x) NSLog(#"%#", x)
how can I call it and format the string in the macro argument like this
A([NSString stringWithFormat:#"Random string with number %d", 5]);
I am getting error too many arguments provided to function-like macro invocation and the error marker points to the comma, which makes sense, since I assume that is there the preprocessor splits the arguments, since it does not know the context that it is a selector call. Is it even possible to do this?
As the linked question's answer says, the solution lies in using an extra pair of paranthese at the call site:
A(([NSString stringWithFormat:#"Random string with number %d", 5]));
works.

Why does NSDictionary uses = sign inside json objects? [duplicate]

This question already has answers here:
Generate JSON string from NSDictionary in iOS
(14 answers)
Closed 8 years ago.
I am creating a new JSON (NSDictionary) object in Objective-C using various methods such
objectForKey
but when I actually print the NSDictionary object after converting it to NSString, I see that unlike the colon (:) separator, it uses the equals (=) separator between the key and value.
How can I ensure that the NSDictionary uses the : as a separator between the key and value?
It is just a formatting issue. If you create an NSJSON obkect from it, that object will be in correctly formatter JSON. When you log NSDictionary to console or otherwise print it, it uses some custom formatting, probably unrelater to the actual internal structure.

Where to store strings for iOS app [duplicate]

This question already has answers here:
Constants in Objective-C
(14 answers)
Closed 8 years ago.
I have an iOS app that requires me to have a "bank" of multiple strings. What I mean is that I need to have several strings that I can call upon at any time. Here is what I am thinking of.
// Strings.h
#define STR_ONE #"1"
#define STR_TWO #"2"
// ...
And when I need to use these strings, I simply include the header file. I chose to go with a header file because there will be many of these strings, and I just wanted to keep them separate.
So the question: Is this the best approach to solve my problem? Are there any alternate (and better) ways that I am missing?
Side notes: Is there any memory management I need to be thinking about here?
Should this be written to a file, and drawn upon from there?
Thankyou
NSArray: you can store a fixed amount of string insiden an array
NSArray* nameArr = [NSArray arrayWithObjects: #"Jill Valentine", #"Peter Griffin", #"Meg Griffin"
NSMutableArray: this type of array can expand and decrease in size.
NSMutableArray *names = [[NSMutableArray alloc] init];
[self.names addObject:#"Harry Potter"];
If the amount of Strings is not enorm, a simple Plist will work for you. But i also would recommend you to read about core data.
Property List Link

why is NSNumber numberWithDouble adding 0's to a number in objective-c [duplicate]

This question already has answers here:
exact representation of floating points in c
(9 answers)
Limiting decimal points to what is needed [duplicate]
(2 answers)
Closed 9 years ago.
I'm using xcode. I have something like this in my code
NSNumber *a=[NSNumber numberWithDouble:[#"0.07" doubleValue]];
//after that line a value is 0.07000000000000001
NSNumber *a=[NSNumber numberWithDouble:[#"0.099999999999999" doubleValue]];
// after that line a value is 0.09999999999999901
I found these 2 exceptions. Others numbers are working fine.
How can I fix it?
i need to convert a string in a nsnumber, but this is trowing my a wrong number i need a value to be 0.07 equal as the string number.
This number will be typed by the user and i need to show later the number exactly how he typed it, i cant rounding it with a formatter, because i don't know the quantity of decimals that the user type.

How is my string potentially unsecure? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Calling NSLog from C++: “Format string is not a string literal (potentially insecure)”
Why is my string potentially unsecure in my iOS application?
I have this code to log the number of elements in my NSMutableDictionary called "myDictionary" in objective-c.
NSLog([NSString stringWithFormat:#"%d", [myDictionary count]]);
XCode warns me that "Format string is not a string literal. Potentially insecure."
Why? Aren't I using a secure formatted string as opposed to directly casting the count?
NSLog() already assumes that you'll be passing in a formatted string. Try this instead:
NSLog(#"%d", [myDictionary count]);
The string you pass to NSLog is interpreted like a format string, so the appropriate way to do this is NSLog(#"%d", myDictionary.count);.
The reason it's "unsafe" is that it's possible to crash the program in cases like this:
NSString *someString = #"The integer format specifier is %d";
NSLog([NSString stringWithFormat:#"%#", someString]);
The input to NSLog is treated like a format string, but there's no corresponding value for the %d at the end. In your case it's not a problem, but the compiler isn't smart enough to figure that out.