objective c - iOS what is difference between Different type of app delegate? -
i beginner in ios , know basic question creates confusin many times me , faced several issue due app delegate declaration. difference between type of appdelegate declaration , when declared it?
1) when declared appdelegate object .
//in viewcontroller.h file #import "appdelegate.h" #import "friendsviewcontroller.h" #import "xmppstream.h" @class appdelegate; @interface viewcontroller :uiviewcontroller<xmppstreamdelegate,uitextfielddelegate, uialertviewdelegate, uiapplicationdelegate> { uiview *padding; appdelegate *appdelegate; }
2) when declared appdelegate in properties.
//in viewcontroller.h file @property (weak, nonatomic) appdelegate *appdelegate;
3) when declare appdelegate in viewcontroller.m file make object.
//in viewcontroller.m file uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:[nsbundle mainbundle]]; appdelegate *appdelegate = (appdelegate *)[[uiapplication sharedapplication] delegate];
4) when declare appdelegate this
// in viewcontroller.m file +(appdelegate *) sharedappdelegate { return (appdelegate *) [uiapplication sharedapplication].delegate; }
difference
- (appdelegate *)appdelegate { return (appdelegate *)[[uiapplication sharedapplication] delegate]; }
i know basic question many people me face difficulty declare.
first 1 used create private object of class.
appdelegate *appdelegate;
second 1 used create public , global object of class, used property attributes.
@property (weak, nonatomic) appdelegate *appdelegate;
but first 2 object declaration third, fourth , fifth same, differance dot(.) used getter , setter method, square brackets shows not property, instead class method of class.
in declared object passing instance of appdelegate
4th case class methods
, 5th case instance method
appdelegate *appdelegate = (appdelegate *)[[uiapplication sharedapplication] delegate]; //or appdelegate *appdelegate = (appdelegate *) [uiapplication sharedapplication].delegate;
Comments
Post a Comment