In the above snippet,you are just declaring a variable for which you have to declare or write accessors yourself
setValue: and value
Using @property will declare your accessors for you and is equivalent to declaring setvalue: and value yourself.
It is the recommended way to declare accessors since Objective-C 2.0. Note that you still have to declare the property (in your case value) yourself.
Why properties are made nonatomic in Objective C?
Best Tutorials- Properties in objective C
As mentioned above,@property only declares the accessors for your property or variable, @synthesize will implement them.If you declare @property in your @interface you mostly likely write an @synthesize in @implementation.
Using @synthesize is equivalent to implementing setValue: and value.
The attributes (nonatomic, retain) tell the compiler, among others, how the memory management should work and therefore how the methods will be implemented.
You never actually see these accessors, but be assured that they are there and ready for you to be used.
Basically it is a category and allows adding methods in the .m file. The best way is to use a Class Extension, the syntax is similar just the "Private" is missing, just two parentheses.
The additional advantage of a class extension is that properties can also be included and the compiler will validate that all methods declared are defined.
A class definition starts with the keyword @interface followed by the interface(class) name; and the class body, enclosed by a pair of curly braces.
In Objective-C, all classes are derived from the base class called NSObject. It is the superclass of all Objective-C classes. It provides basic methods like memory allocation and initialization. For example, we defined the Box data type using the keyword class as follows:
Explain the role of UIKit in iOS Development.
The UIKit framework is plays a main role in designing or building user interface.
UIKit framework gives us event handling, drawing model, windows, views, and controls, basically designed for a touch screen interface.
The UIKit framework provides the important infrastructure needed to build and manage iOS apps.
Let’s point out some features provided by UIKit
Window and view architecture to manage an app’s user interface,
Event handling infrastructure to respond to user input, and
An app model to drive the main run loop and interact with the system.
UIKit supports the following features:
A view controller model to encapsulate the contents of your user interface
It provides Support for handling touch-and motion-based events
It supports for a document model that includes iCloud integration
It provides graphics and creating window support, including support for external displays
It supports for managing the app’s foreground and background execution
It Provides printing support
It supports for customizing the display of standard UIKit controls
It gives support for text and web content
It supports for cutting, copying, and paste support
It supports for animating user-interface content
It gives support for integrating other apps on the system through URL schemes and framework interfaces
It gives accessibility support for disabled users
It support for the Apple Push Notification service
It supports for local notification scheduling and delivery
It provides PDF creation
It provides support for using custom input views that behave like the system keyboard
It supports for creating custom text views that interact with the system keyboard
It supports for sharing content through email, Twitter, Facebook, and other services
Basic iOS interview Questions And Answers
Top 5 Frequently Asked iOS Interview Questions And Answers.
3.What are different ways that you can specify the layout of elements in a UIView?
You can create and add XIB file into your Xcode project and layout elements within it.
Then,you can load the XIB in your application code automatically or manually based on naming conventions.Also,using interface builder you can add storyboard for your application.
Alternatively, using only code you can use NSLayoutConstraints to have elements in a view arranged by Auto Layout. Finally, you can create CGRects describing the exact coordinates for each element and pass them to UIView's - (id)initWithFrame:(CGRect)frame method.
iOS Interview Questions And Answers Part13
4.Explain different ways of achieving concurrency in OS X and iOS.
You can achieve concurrency in iOS basically in three ways:
You can achieve concurrency using threads but there are some disadvantages using threads:1.It’s not a scalable solution for developers.You need to predict how many threads to create and adjust them dynamically as conditions change.It creates a burden of creating and maintaining the threads it uses.
So,you should prefer asynchronous design approach to solve concurrency problem rather than relying on threads in OSX or iOS.
GCD (Grand central dispatch):
GCD starts tasks asynchronously and relegates thread management down to the system level. All you need to do is define the tasks to be executed and add them to the appropriate dispatch queue. GCD takes care of creating the needed threads and scheduling tasks to run on those threads.
All dispatch queues are first-in, first-out (FIFO) data structures, so tasks are always started in the same order that they are added.
An operation queue is the Cocoa equivalent of a concurrent dispatch queue and is implemented by the NSOperationQueueclass. Unlike dispatch queues, operation queues are not limited to executing tasks in FIFO order and support the creation of complex execution-order graphs for your tasks.
iOS Interview Questions And Answers For 1-2 years Experienced Candidates.
5.Between atomic and non-atomic properties, which is the default for synthesized properties? When would you use one vs the other?
atomic happens to be the default state for synthesized properties.
If you have a property for which you know that retrieving an uninitialized value is not a risk (e.g. if all access to the property is already synchronized via other means), then setting it to nonatomic can gain you a bit of performance.
iOS Interview Questions And Answers Part 25