If Google doesn't accept your app for the play store, or you don't like their conditions, you could still offer it through alternative means, e.g. Amazon Market, AndroidPIT etc. or just sell it on your own website (*). Additionally, since Apple has strict requirements regarding content etc., and enforces them, your app is more likely to be rejected by Apple than by Google.
Android in general allows your app to dig deeper into the system. On iOS, your app simply cannot get the permission e.g. to kill other apps.
(*) Gameloft offered their Android games only through their website for a long time, so it's not a purely hypothetical option.
I avoid using UITableViewController
, as it puts lots of responsibilities into a single object. Therefore I separate the UIViewController
subclass from the data source and delegate. The view controller's responsibility is to prepare the table view, create a data source with data, and hook those things together. Changing the way the tableview is represented can be done without changing the view controller, and indeed the same view controller can be used for multiple data sources that all follow this pattern. Similarly, changing the app workflow means changes to the view controller without worrying about what happens to the table.
I've tried separating the UITableViewDataSource
and UITableViewDelegate
protocols into different objects, but that usually ends up being a false split as almost every method on the delegate needs to dig into the datasource (e.g. on selection, the delegate needs to know what object is represented by the selected row). So I end up with a single object that's both the datasource and delegate. This object always provides a method -(id)tableView: (UITableView *)tableView representedObjectAtIndexPath: (NSIndexPath *)indexPath
which both the data source and delegate aspects need to know what they're working on.
That's my "level 0" separation of concerns. Level 1 gets engaged if I have to represent objects of different kinds in the same table view. As an example, imagine that you had to write the Contacts app—for a single contact, you might have rows representing phone numbers, other rows representing addresses, others representing email addresses, and so on. I want to avoid this approach:
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
id object = [self tableView: tableView representedObjectAtIndexPath: indexPath];
if ([object isKindOfClass: [PhoneNumber class]]) {
//configure phone number cell
}
else if …
}
Two solutions have presented themselves so far. One is to dynamically construct a selector:
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
id object = [self tableView: tableView representedObjectAtIndexPath: indexPath];
NSString *cellSelectorName = [NSString stringWithFormat: @"tableView:cellFor%@AtIndexPath:", [object class]];
SEL cellSelector = NSSelectorFromString(cellSelectorName);
return [self performSelector: cellSelector withObject: tableView withObject: object];
}
- (UITableViewCell *)tableView: (UITableView *)tableView cellForPhoneNumberAtIndexPath: (NSIndexPath *)indexPath {
// configure phone number cell
}
In this approach, you don't need to edit the epic if()
tree to support a new type - just add the method that supports the new class. This is a great approach if this table view is the only one that needs to represent these objects, or needs to present them in a special way. If the same objects will be represented in different tables with different data sources, this approach breaks down as the cell creation methods need sharing across the data sources—you could define a common superclass that provides these methods, or you could do this:
@interface PhoneNumber (TableViewRepresentation)
- (UITableViewCell *)tableView: (UITableView *)tableView representationAsCellForRowAtIndexPath: (NSIndexPath *)indexPath;
@end
@interface Address (TableViewRepresentation)
//more of the same…
@end
Then in your data source class:
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
id object = [self tableView: tableView representedObjectAtIndexPath: indexPath];
return [object tableView: tableView representationAsCellForRowAtIndexPath: indexPath];
}
This means that any data source that needs to display phone numbers, addresses etc. can just ask whatever object is represented for a table view cell. The data source itself no longer needs to know anything about the object being displayed.
"But wait," I hear a hypothetical interlocutor interject, "doesn't that break MVC? Aren't you putting view details into a model class?"
No, it doesn't break MVC. You can think of the categories in this case as being an implementation of Decorator; so PhoneNumber
is a model class but PhoneNumber(TableViewRepresentation)
is a view category. The data source (a controller object) mediates between the model and the view, so the MVC architecture still holds.
You can see this use of categories as decoration in Apple's frameworks, too. NSAttributedString
is a model class, holding some text and attributes. AppKit provides NSAttributedString(AppKitAdditions)
and UIKit provides NSAttributedString(NSStringDrawing)
, decorator categories that add drawing behaviour to these model classes.
Best Answer
Yes, NDK will add a layer of complexity. But it will probably be worth it.
If your drawing is done in c++, then you better implement your model in C++ too. That gives you less code to rewrite for iOS and less code to maintain.
Luckily (in this case) OpenGL is state machine, so it is fairly simple to set up the rendering context in java (being close to the GUI code) and then pass control to C++ for the actual OpenGL drawing calls.
Implementing an NDK (JNI) interface is quite repetitive. It might feel ugly to set up your first three classes or so. After that you'll get the hang of it and it is just interface desig and typing code.