I am actually a newby at xcode. I can make out a few things be myself but have questions about what some things do and why they are put there. I have tried to read many e-books, watched tutorials, but they never go into the basics, alway just say “Add this, Click here etc”
Could someone give me some answers to a few questions please.
Ok, I know an ios app is mostly made out of Views, views are controlled by controllers. Each controller has a header (.h) file and a module?class? file (.m). The .h file contains the declarations of variables and functions used in the .m file.
The whole app is controlled by a master “controller” called the “delegate”.
Definitions in .h file may be for example an action IBAction or IBLabel or something.
What raises questions for me is for example these lines:
@class FlipsideViewController;
@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end
@interface FlipsideViewController : UIViewController
@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
and why are sometimes in another view controller the delegate class loaded
@class MainViewController;
what does the following do, meaning what is the @interface declaration?
@interface flipAppDelegate : NSObject <UIApplicationDelegate>
what is
nonatomic, retain
sorry for asking really stupid questions, but every tutorial just skips these things.
I can follow a youtube video or a manual, but it doesn’t teach me a lot…
Let me try to answer your questions, one at a time.
The interface declares a class. By declaring a class, I mean it specifies the instance variables and private/public methods that it contains. Again, the header file only contains the declaration of the methods, and the implementation/body of the methods lies in the module class. So, here-
The class
FlipsideViewControllerderives from/subclasses/extendsUIViewController. i.e Is a type ofUIViewControllerbut adds its own features.Similarly
Subclasses NSObject and implements the
UIApplicationDelegateprotocol. A protocol is essentially a set of methods that a class promises to implement (although there can be optional methods).The delegate pattern allows a class to delegate its work to another class that implements the delegate protocol. So, here,
FlipsideViewControllerkeeps an instance of the delegate object, so that itsflipsideViewControllerDidFinish:can be called.It means that when you set a value to your instance variable, the value’s refcount will be incremented and set to your variable. Also, it will not happen as an atomic operation. You need atomic only in a multi-threaded environment.
@synthesize is simply a shortcut to generate getters and setters for your variables.