Post on 19-Aug-2020
An Introduction to Android for iOS Developers
Simon D. LevyCSCI 251
12 May 2014
DISCLAIMER ...
Android vs. iOS: Consumer
Perspective
(worldwide)
forbes.com
forbes.com
UnixNon-Unix
http://en.wikipedia.org/wiki/File:Unix_history-simple.svg
Consumer Perspective:
Devices
http://www.digitaltrends.com/
http://www.cnet.com/
http://www.cnet.com/
Samsung T9000
Google Project Ara
Developer Perspective:
Distribution Model
Walled Garden
Curated Computing
Wild West!
Wild West?
http://en.wikipedia.org/wiki/Walled_garden_%28technology%29
Fee Structure
Getting your app onto your device: Provisioning
Getting your app onto your device: Provisioning
The Power of Open Standards
Reverse Engineering
Developer Perspective:
OS
http://developer.apple.com
http://en.wikipedia.org/wiki/Android_os
Developer Perspective:
IDE
Ancestry: NeXT
Developer Perspective:Language
CSmalltalk
Objective-CC++
Simula
1960
1970
1980
1990
2000
Java
Memory AllocatiomC++: Explicit deallocaction
void mymethod(){
Circle * circ = new Circle(3,4,2);…
delete circ;}
Memory AllocatiomJava: Garbage-collected
void mymethod(){
Circle circ = new Circle(3,4,2);…
} // circ automatically deallocated now
Memory Allocatiom● Objective-C: Reference counting (“semi-automatic”
garbage collection)
NSString* s = [[NSString alloc] init]; // Ref count is 1[s retain]; // Ref count is 2 - silly // to do this after init[s release]; // Ref count is back to 1[s release]; // Ref count is 0, s is freed
http://stackoverflow.com/questions/6578/understanding-reference-counting-with-cocoa-and-objective-c
● Xcode (4.2 and later) provides Automatic Reference Coutning (ARC), making this largely unnecessary
Inheritance● C++: Multiple inheritance
class Apple : Fruit, Edible{
};
● Experienced programmers avoid this, using composition (has-a) instead of inheritance (is-a).
Inheritance● Java: Single inheritance + interfaces
class Apple extends Fruit, implements Edible{
}
Inheritance● Objective-C: Single inheritance + protocols
@interface MyClass : NSObject <MyProtocol>
...
@end
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols.html
Method Invocation C++, Java
● Invoke an object's method● “Tight” association between method
and class ● Compiler makes sure that class
implements method
circ.move(-3,5);
Method InvocationObjective-C
● Send a message to an object● “Looser” association between method
and class ● Object can ignore message (runtime
constraints; programmer didn't implement method)
[circ moveX:-3 andY:5];
Reflection
● Java: We can query the type (class) of an object at runtime:
System.out.println(c.getClass());
Reflection● Objective-C: We can also check which
messages the object responds to:
http://stackoverflow.com/questions/4574465/objective-c-respondstoselector-question
if ([c respondsToSelector:@selector(move:)]){
}
if([c isKindOfClass:[NSString class]]){
}