Questions 8 to 12 in 50
Page 2
What are Wildcard App IDs?
A wildcard app ID allows you to use an app ID to match multiple apps; wildcard app IDs are useful when you first start developing new apps
because you don’t need to create a separate app ID for each app. However, wildcard app IDs can’t be used to provision an app that uses APNS,
In-App Purchase, or Game Center.
A wildcard app ID omits some or all of the bundle ID in the search string and replaces that portion with an asterisk character (*). The asterisk must always appear as the last character in the bundle search string.
When you use a wildcard app ID, characters preceding the asterisk (if any) must match the characters in the bundle ID, exactly as they would for an explicit app ID. The asterisk matches all remaining characters in the bundle ID. Further, the asterisk must match at least one character in the bundle ID. This table shows an example search string and how it matches some bundle IDs but not others.
If an app id uses an * as the bundle ID, then the search string matches any bundle ID.
A wildcard app ID omits some or all of the bundle ID in the search string and replaces that portion with an asterisk character (*). The asterisk must always appear as the last character in the bundle search string.
When you use a wildcard app ID, characters preceding the asterisk (if any) must match the characters in the bundle ID, exactly as they would for an explicit app ID. The asterisk matches all remaining characters in the bundle ID. Further, the asterisk must match at least one character in the bundle ID. This table shows an example search string and how it matches some bundle IDs but not others.
If an app id uses an * as the bundle ID, then the search string matches any bundle ID.
What are categories in iOS?
We use categories to define additional methods of an existing class even one whose source code is unavailable to you without subclassing.
You typically use a category to add methods to an existing class, such as one defined in the Cocoa frameworks. The added methods are inherited
by subclasses and are indistinguishable at runtime from the original methods of the class. You can also use categories of your own classes to:
Distribute the implementation of your own classes into separate source files for example, you could group the methods of a large class into several categories and put each category in a different file.
Declare private methods.
You add methods to a class by declaring them in an interface file under a category name and defining them in an implementation file under the same name. The category name indicates that the methods are an extension to a class declared elsewhere, not a new class.
Distribute the implementation of your own classes into separate source files for example, you could group the methods of a large class into several categories and put each category in a different file.
Declare private methods.
You add methods to a class by declaring them in an interface file under a category name and defining them in an implementation file under the same name. The category name indicates that the methods are an extension to a class declared elsewhere, not a new class.
What is Delegation in iOS?
Delegation is a design pattern in which one object sends messages to another object specified as its delegate to ask for input or to notify it
that an event is occurring. Delegation is often used as an alternative to class inheritance to extend the functionality of reusable objects.
For example, before a window changes the size, it asks its delegate whether the new size is ok. The delegate replies to the window, telling it
that the suggested size is acceptable or suggesting a better size.
How can we achieve a singleton pattern in iOS?
Delegation is a mechanism by which a host object embeds a weak reference (weak in the sense that it’s a simple pointer reference, unretained)
to another object its delegate and periodically sends messages to the delegate when it requires its input for a task. The host object is
generally an “off-the-shelf” framework object that is seeking to accomplish something but can only do so in a generic fashion. The delegate,
which is almost always an instance of a custom class, acts in coordination with the host object, supplying program-specific behavior at certain
points in the task (see Figure 4-3). Thus delegation makes it possible to modify or extend the behavior of another object without the need for
subclassing.
What are all the differences between categories and subclasses? Why should we go to subclasses?
The category is a feature of the Objective-C language that enables you to add methods (interface and implementation) to a class without having
to make a subclass. There is no runtime difference within the scope of your program between the original methods of the class and the methods
added by the category. The methods in the category become part of the class type and are inherited by all the class’s subclasses. As with
delegation, categories are not a strict adaptation of the Decorator pattern, fulfilling the intent but taking a different path to implement
that intent. The behavior added by categories is a compile-time artifact, and is not something dynamically acquired. Moreover, categories do
not encapsulate an instance of the class being extended. The Cocoa frameworks define numerous categories, most of them informal protocols.
Often they use categories to group related methods. You may implement categories in your code to extend classes without subclassing or to
group related methods. However, you should be aware of these caveats:
- You cannot add instance variables to the class.
- If you override existing methods of the class, your application may behave unpredictably.