Combining two strings for a label's text [duplicate] - objective-c

This question already has answers here:
Setting a cell's text with multiple JSON objects
(3 answers)
Closed 9 years ago.
Real beginners question here. I'm doing some tutorials and I'm expanding on them with scenarios that might come in to play.
Anyhow, I know that the following works:
lblCopyStatus.text = #"Test";
But how would do:
lblCopyStatus.text = #"Test" & lbltest.text;
e.g. get the text from another label into the text. I hope that makes sense :)

For example:
lblCopyStatus.text = [NSString stringWithFormat:#"Test %#", lbltest.text];

Related

Objective C syntax, iOS sample code [duplicate]

This question already has answers here:
What does a type name in parentheses before a variable mean?
(3 answers)
Closed 8 years ago.
I'm learning objective-C and I was looking at some sample code from:
https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Listings/SamplePhotosApp_AAPLAssetGridViewController_m.html#//apple_ref/doc/uid/TP40014575-SamplePhotosApp_AAPLAssetGridViewController_m-DontLinkElementID_8
I'm confused about this line of code here:
CGSize cellSize = ((UICollectionViewFlowLayout *)self.collectionViewLayout).itemSize;
I understand that it's trying to get the itemSize property and store it into cellSize, but I have no idea what ((UICollectionViewFlowLayout *)self.collectionViewLayout) is all about. Can someone break it down for me? Is there another way to write this line of code?
What it means is:
Cast self.collectionViewLayout to be of UICollectionViewFlowLayout type. Then of self.collectionViewLayout get the itemSize property. Finally, save everything is a property of type CGSize.
I believe is a elegant and concise way of writing it.

Get text from NSTextField [duplicate]

This question already has answers here:
Get value from NSTextField
(4 answers)
Closed 8 years ago.
I'm new to OS X development in Xcode and was wondering how to get the text from a text field and NSLog it, I would also like to pass it to a string. Any help?
The -stringValue method can be used.
NSTextField *myTextField = [[NSTextField alloc] initWithFrame:...];
NSString *text = [myTextField stringValue];
NSLog(#"%#", text);
Do not be fooled by those who say that text is a property of NSTextField.
Before asking questions like this, please read up on the documentation here:NSTextView. Also please take a look at all of Apple's documentation here:Apple Documentation

Creating an object and setting a property in one line or two [duplicate]

This question already has answers here:
What's the difference between dot syntax and square bracket syntax?
(5 answers)
Closed 9 years ago.
I want to set a property but I'm not sure what is the best way to do it. I can think of two ways to do this. By creating an object, storing it in a variable, and setting the property:
PropertyClass *myProperty = [[PropertyClass alloc] init];
self.myClassProperty = myProperty
Or by creating and setting in one line:
self.myClassProperty = [[PropertyClass alloc] init];
Are there any reasons one way is actually better/safer/faster/etc.? Is there a better way than the two I listed above? I'm not sure if this makes a difference but this would be the first time the property is set.
They are equal but I always use the second one. Or the following
self.myClassProperty = [PropertyClass new];
The reason - in one line of code it is more difficult to make some stupid error. Also it is easier to read.

UILabel.text == self.NSString? [duplicate]

This question already has answers here:
Compare two NSStrings
(3 answers)
Closed 9 years ago.
My question may be simple for some to answer, but I'm relatively new to Objective C and Xcode. So I have a UILabel and I am running an if statement asking if UILabel is equal to self.NSString then do ... Here is the code.
if (UILabel.text == self.NSString)
{
//Do Something here...
}
I'm wondering if this would work, or what I have to do in order for this to start working.
Thanks in advance.
Use isEqualToString: method from NSString class.
if([text isEqualToString:string])
{
// Do something here.
}
When comparing strings, you should use
[UILabel.text isEqualToString:self.NSString]
The == simply compares the pointers, which will often be different even if their contents are the same. The isEqualToString method compares the contents.

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

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;