As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
The syntax is legal. It'll save you about 2 seconds every time you alloc/init an object. Do you think this could be a new trend?
Again,
NSObject *obj = NSObject.alloc.init;
[NSObject new];
Saves even more and doesn't cause any religious wars.
Yes, it saves a few keystrokes, but I doubt it will catch on. See this blog post for a number of cases where using dot notation on methods rather than properties will not work. I think most people view this as a side effect of ObjC2.
Furthermore, I don't think it enhances readability at all. As soon as you want to send a message with an argument, you have to revert back to the original syntax.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
One of the disadvantages of inheritance is that the superclass and its subclasses are very tightly coupled. A lot of resources (e.g. SO) say to compensate for this by being 'cautious' when writing a class that might be subclassed.
Are there any guidelines about what precautions you should take, or testing processes to go through to make sure your base class is safe? Or do you just have to try to predict all potential subclass behavior?
Do as little as required in the parent classes. If you must do more complex operations then separate them into logical pieces, putting each piece in a different method so that children can override them as appropriate.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm learning this from a 'newish' book, but I'm wondering what the current standard is as to the use of the dot operator for things outside of setting property values.
As in method calls and whatnot. Obviously myClass.myMethod:value is syntactically correct, but is it an accepted norm nowadays?
The dot operator is much more 'human' feeling than [myClass myMethod:myValue] in my opinion.
Have you tried compiling this? Your example of myClass.myMethod:value is not valid as far as I understand it.
The dot operator is translated by the compiler to either -(void)setMyValue:(ValueType*) or -(ValueType*)myValue depending on if you are getting or setting it.
Read the apple documentation for more info:
http://developer.apple.com/library/ios/documentation/cocoa/conceptual/objectivec/Chapters/ocObjectsClasses.html#//apple_ref/doc/uid/TP30001163-CH11-SW17
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I seem to be coming across a lot of variable (boolean) for some Options that control whether something will be done, like:
GiveWarningEnabled
FeedbackEnabled (will provide feedback)
These will be used a lot and I"m trying to think of a good pre/suf fix that will indicted it's Boolean. My best thought so far was Enabled.
Perhaps: Will?
WillGiveWarning (or WillWarn)
WillGiveFeedback?
often times "is" will be used, such as isPlaying or isWifiEnabled.
Will, should, can, and does are also good ones to use because they express conditions. A verb such as "give", like the one you listed, seems to better fit a function declaration since it is performing an action.
I usally prefer flag.
Example:
warningFlag,
feedbackFlag.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Imagine an ordinary UIViewController subclass. We want to do "setup stuff" to be preformed before -viewDidWhatever, but the problem is that there are three methods that could possible be called, either -initWithNibName, -initWithCoder or simply -init depending on how it is created.
The solution would be to create -setup to be called from all these three, but I'm a bit unsure about the name. My question to you is: is there any standard naming of this method?
I have commonly named it -setup myself when doing this.
Depending on what you want to do, you could put it in + (void)initialize, which is inherited from NSObject and will automatically be called before the class receives its first message.
Have a look here: Apple Developer Library: NSObject Class Reference
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
To better understand ARC I'm looking for example code that compiles perfectly with ARC enabled , but crashes at runtime. Ie the common pitfalls that may be overlooked and can cause you a debugging nightmare if you've never encountered that issue before.
Real life examples tuned down to the minimum code that reproduces the issues would be very helpful. In particular if the ARC code is interfacing with C or C++ code.
Quick example of the many I was thinking along the same lines as bbum.
Casting from CF... to NS... confuses ARC if done incorrectly for example:
CFArrayRef *supportedInterfaces = CNCopySupportedInterfaces();
NSArray *interfaceNames = (__bridge_transfer NSArray *)supportedInterfaces;
CFRelease(supportedInterfaces);
Would over-release supportedInterfaces since __bridge_transfer retains the NSArray while releasing the CFArrayRef. In this case either don't use the CFRelease() or use plain __bridge.