Text length in Objective-C - iphone

Please tell me the difference between test.length and [test length]?
Which is more usefull for iOS developement?

No difference in meaning, they both access length property.
Their only difference is syntactic.
Check Apple documentation about sending a message to an object

test.length is just a convenience syntax introduced in Objective C 2.0. The two expressions you list are totally equivalent and a matter of preference more than anything else.

They are the same. Sometimes it may (!) be better to use one or the other for readability of your code.

Related

What does encapsulation do for clearing up the type of a variable or constant?

I'm currently reading through Apple's "Intro to App Development with Swift" student guide. At the end-quiz of chapter 9, "Types", it asks:
When you're reading code and aren't sure of the type of a variable or constant, what's the quickest way to find out?
The answer is:
Rewrite the section of code using different encapsulation.
However, the concept of encapsulation has not been introduced before so I'm rather confused. In the e-book's Glossary, it states:
A language mechanism for restricting access to some of the object components and/or a language construct that facilitates the bundling of data with the methods of operating on that data.
Can anyone explain how this relates to finding out about the type of a variable or constant?
Thanks in advance.
The answer is:
Rewrite the section of code using different encapsulation.
That's a wrong answer. The right answer is "Use Xcode's [Quick Help] inspector."
Can anyone explain how this relates to finding out about the type of a variable or constant?
The suggestion here is that if you rewrite the source to make a private variable public (i.e. change the way it is encapsulated) it would make it easier to find the type of the variable in question.

Duplicate declaration of method objective-c

This question may be duplicate of the Objective C - "Duplicate declaration of method" compilation error
But i am still confuse for why objective C dose not support the function Overloading / method overloading
Can any one tell me the proper reason for why this error occur?
objective-C does not support method overloading, so you have to use different method names.
Simply because Objective-C doesn't support overloading. And besides it is highly recommended to include the types of the arguments in the function's name, whenever possible. Try getTextFromTextView: and getTextFromTextField: instead.
I want to tell you please check the "How to define method ?", You can found in above link about multiple input method also. and this one is for naming conventions of method in Objective C?
As per above we can know that your method have same name(Signature) as getText:
In your case there are duplicated method you define which is not supported by objective C Compiler.
Hope this one helpful to you.
read this thread that why objective c does not suport method overloading
Why Objective-C doesn't support method overloading?
and this is apple discussion form
https://discussions.apple.com/thread/512569?start=0&tstart=0

Naming conventions on IBAction functions

I am doing another iOS application and I wonder if there are any naming conventions or good practices on how to name actions that I could follow. I am thinking of names on the functions that are invoked when user e.g. touches a button.
Go with Apple's guidelines. What were in the past good suggestions have now been codified in ARC (Automatic Reference Counting) and are necessary to be followed for ARC to generate correct code. Using these guidelines may well future-proof your code, it did for ARC!
Apple's guidelines
Coding Guidelines for Cocoa
From the method naming section:
Start the name with a lowercase letter and capitalize the first letter of embedded words. Don’t use prefixes.
There are two specific exceptions to these guidelines. You may begin a method name with a well-known acronym in uppercase (such as TIFF or PDF)), and you may use prefixes to group and identify private methods
For methods that represent actions an object takes, start the name with a verb.
- (void)invokeWithTarget:(id)target;
- (void)selectTabViewItem:(NSTabViewItem *)tabViewItem
Do not use “do” or “does” as part of the name because these auxiliary verbs rarely add meaning. Also, never use adverbs or adjectives before the verb.
If the method returns an attribute of the receiver, name the method after the attribute. The use of “get” is unnecessary, unless one or more values are returned indirectly.
- (NSSize)cellSize;
Use keywords before all arguments.
- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag
Make the word before the argument describe the argument.
- (id)viewWithTag:(int)aTag;
I haven't come across much in the way of specifics when it comes to naming conventions for IBActions. However, if you were to follow the trend Apple seems to be setting in its sample apps, then some examples are as follows:
-(IBAction)cameraAction:(id)sender;
-(IBAction)done:(id)sender;
-(IBAction)takePhoto:(id)sender;
Hope this helps.
I guess any method name in Objective - C should be readable like you reading an english sentence. Lets say below method.
[fileWrapper writeToFile: path atomically: YES updateFilenames: YES];
// This is not a real example but purpose of sharing is to make sure
method name is readable, so programmers can actually read code and can
have SmallTalk.
When you read left to right it helps you to read and explains it self what it is going to do.
Check out this below link,
http://cocoadevcentral.com/articles/000082.php
Jump on page No. 5 of 7
There are lots of tips has been given. More tips can be found in Apple's developer library.
Happy Coding
Here is a discussion about how to name IBAction functions/methods.

Creating Macro's in C#

Is there a way to create macros in c#
ex:
string checkString = "'bob' == 'bobthebuilder'" (this will be dynamic)
if (##checkString)
//.........
else
//.........
Thanks
No, C# doesn't have macros. You could capture your logic in a delegate and apply that delegate in multiple places, potentially... would that help?
If you could describe the problem you're trying to solve rather than the solution you think you'd like, we may be able to help more.
T4 seems to be gaining traction these days for .NET work. It's not quite what you asked for, but it may be extremely beneficial in some cases (or it may just be a hint down the wrong path).
In most cases, esp. with generics, I do not wish for 'templates' or 'macros' in C# (or Scala). In the example above, you could simply use:
bool sameStuff = "'bob' == 'bobthebuilder'";
...
if (sameStuff) {
...
}
More complex cases can generally be dealt with refactoring methods or using anonymous functions.
Additionally, attributes (while a completely different approach) round out the case for many "traditional" uses of templates.
As mentioned, no, but there are a number of other approaches:
Conditional compilation via #if
Templating via T4 or something else (we use a port of Ned Batchelder's (mentioned) Cog
Aspect-Oriented Programming via something like PostSharp
As Jon said, lots of ways; it'd be better to describe exactly what you want to do.
Short answer: No.
Long answer: You can write a wrapper around the C/C++ compiler's preprocessor.
Most of the syntax will be accepted with the notable exception of #region/#endregion. You can just prefix those with #pragma before processing, and remove the #pragma part afterwards.

What data type do I use for an integer in SOAP XML in Cocoa?

I imagine it is just an int, but I want to verify.
Thanks
Corey
I would suggest using NSInteger/NSUInteger instead of int. NS(U)Integer maps to the appropriate size based on the environment you are running in. It might not matter much for the current iPhones/iPods, but you might as well future proof your code. See CocoaDev for further discussion.
Yes, just an int.