Objective-C for Experienced Programmers
|
|
|
- Allan Horton
- 10 years ago
- Views:
Transcription
1 Objective-C for Experienced Programmers Venkat Subramaniam twitter: venkat_s Objective-C An Object-Oriented extension to C If you re familiar with C/C++/Java syntax, you re at home Though you are closer to home if you know C++ :) If you re used to VB.NET/Ruby/... then you need to get used to the curly braces and the pointers The biggest challenge is to learn and to remember to manage memory Following certain practices will ease that pain Objective-C 2
2 A Traditional HelloWorld! #import <Foundation/Foundation.h> // or stdio.h int main (int argc, const char * argv[]) { printf("hello World!\n"); return 0; Objective-C 3 printf Variable Types %i Integer %c Character %d Signed decimal Integer %e Scientific notation using e character %E.. using E character %f Floating-point decimal %g The shorter of %e or %f %G The shorter of %E or %f %s String %@ to print an object %u Unsigned decimal integer Objective-C 4
3 Data Types char A char 1 byte (8 bits) double float Double precision 8 bytes float Floating point 4 bytes int Integer 4 bytes long Double short 4 bytes long long Double long 8 bytes short Short integer 2 bytes Objective-C 5 The id type id is a type that can refer to any type of object id vehicle = carinstance; This provides dynamic typing capability in Objective-C You can specify the type if you like or you can leave it to the runtime to figure it out (you use id in the latter case) Objective-C 6
4 nil is an object nil is a special object which simply absorbs calls It will return nil or 0 as appropriate, instead of failing Goe* goe = nil; printf("lat is %g\n", [goe lat]); // will print Lat is 0 Objective-C 7 Behavior of nil Objective-C is very forgiving when you invoke methods on nil This is a blessing and a curse Good news is your App won t blow up if you invoke methods on nil This can also be quite convenient if you don t care to check for nil, call if object exists, otherwise no-bigdeal kind of situation Bad news is, if you did not expect this, your App will quietly misbehave instead of blowing up on your face Objective-C 8
5 NS Objects In Objective-C several classes will start with letters NS These can be included by including Foundation/ Foundation.h NS stands for NeXtStep, creator of Objective-C NextStep was the company that made the Next computers (back in those nostalgic days) Objective-C 9 NSString Regular C style strings are UTF-8 NSString is Objective-C string Supports unicode and several useful operations to create an instance of NSString from a literal You can also use the class method stringwithformat to form a string with embedded values Objective-C 10
6 Creating a NSString #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSString *helloworld World!"; printf("%s\n", [helloworld UTF8String]); NSLog(@"%@", helloworld); [helloworld release]; return 0; Above code has a memory leak in spite of calling release! We ll learn how to fix it real soon. NSLog is a useful tool to log messages. A tool you ll come to rely upon during development. Objective-C 11 Calling a Method [receiver method] format (place your call within []) Use [instance method: paramlist] format to call methods which take parameters For example see how we called UTF8String on the helloworld instance Objective-C 12
7 Creating a Class #import Car : NSObject { (nonatomic) NSInteger miles; -(void) drive: (int) distance; +(int) Objective-C 13 Creating a Class #import Car miles; -(void) drive: (int) distance { miles += distance; +(int) recommendedtirepressure { return Objective-C 14
8 Creating an Instance #import <Foundation/Foundation.h> #import "Car.h" main.m int main(int argc, const char* argv[]) {! Car *car = [[Car alloc] init];! NSLog(@"Car driven %d miles\n", [car miles]);!! [car drive: 10];! NSLog(@"Car driven %d miles\n", [car miles]);!! NSLog(@"Recommended tire pressure %i psi.\n",!! [Car recommendedtirepressure]);!! [car release];! return 0; Objective-C 15 Class and Instance Methods You define instance methods using a - You define class methods using a + Objective-C 16
9 Class Car //... static int tirepressure = 32; +(int) recommendedtirepressure { return Objective-C 17 Multiple Parameters -(void) turn: (int) degreeofrotation speed: (int) speed {! printf("turning %i degrees at speed %i MPH\n", degreeofrotation, speed); Parameters are separated by : [car turn: 20 speed: 50]; Objective-C 18
10 Mystery of Method Names Objective-C method names can contain colons and can have multiple parts. So, when you write setlat: (int) lat lng: (int) lng the actual method name is setlat:lng: and it takes two parameters You call it as [instance setlat: lng: 77.02]; Objective-C 19 Properties Properties are attributes that represent a characteristic of an abstraction They provide encapsulation You have getter and setter methods to access them Objective-C relieves you from the hard work of writing these mundane methods (and their fields) You can use to declare properties To synthesize the getter and setter, creates these methods at compile time, mark to postpone creation to runtime Objective-C 20
11 Property Accessors The getter for a property has the form propertyname The setter for a property has the form setpropertyname setters are not created if you mark your property as readonly You can create custom getters and setters by setting the getter and setter attribute Objective-C 21 Attaching Attribute Flavors You can attach a certain attributes or flavors to a property For (nonatomic, retain) NSString* firstname; Objective-C 22
12 Atomicity Property Attributes nonatomic (default is atomic but there s no keyword for that will incur locking related performance overhead) Setter assign, retain, copy (default is assign, retain will increase retain count on set, release on reassignment) Writability readwrite or readonly (default is readwrite) Objective-C 23 Properties and ivar In the legacy runtime, you need to declare a field with the same name as the property or map it using = in In the modern runtime (64-bit and latest iphone), you don t need a field (ivar) to backup the property. They are generated for you internally Objective-C 24
13 Properties and Person : NSObject (nonatomic, retain) NSString* (nonatomic, retain) lastname; creates firstname and setfirstname: methods creates lastname and setlastname: methods -(void) dealloc { self.firstname = nil; self.lastname = nil; [super dealloc]; Setting this to nil releases the held Objective-C 25 Accessing Properties #import <Foundation/Foundation.h> #import "Person.h" int main (int argc, const char * argv[]) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; Person* dbl07 = [[Person alloc] init]; [dbl07 dbl07.lastname NSString* fname = [dbl07 firstname]; NSString* lname = dbl07.lastname; printf("%s ", [fname UTF8String]); printf("%s\n", [lname UTF8String]); [dbl07 release]; [pool drain]; return 0; You can use either the dot (.) notation or the method call notation [] Objective-C 26
14 Creating an Instance Two step process: First allocate memory (using alloc), then initialize it, using one of the init methods If it takes no parameters, method is often called init If it takes parameters, it gets to be descriptive, like initwithobjects: If you follow the above steps, you re responsible to release the object You can either release it or put that into an auto release pool right after you create Objective-C 27 Make it simple and easy Help users of your class Write your class so we re not forced to use alloc and init Please provide convenience constructors Objective-C 28
15 Convenience Constructors Classes may short-circuit the 2-step construction process and provide a class level convenience method to initialize the instances These methods generally start with name classname... (like stringwithformat: or arraywithobjects: ) If you use a convenience constructor, don t release the instance! These methods add the instance to the autorelease pool for you Objective-C 29 Creating Instances #import <Foundation/Foundation.h> #import "Person.h" int main (int argc, const char * argv[]) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSString* str1 = [[NSString alloc] release"]; NSString* str2 = [[[NSString alloc] autorelease]; NSString* str3 = [NSString worries"]; printf("%s", [[NSString %@ %@", str1, str2, str3] UTF8String]); [str1 release]; [pool drain]; return 0; We ll learn about memory management and release pool soon. Objective-C 30
16 The Magic of init The init method returns self after it does its initialization One benefit is convenience, but the other benefit is morphing You can cascade calls on to the call to init (like [[[Something alloc] init] dowork];) init may actually decide to create an instance of another specialized type (or another instance) and return that instead This allows init to behave like a factory Don t assume init only initializes, you may get something different from what you asked for Objective-C 31 Don t do this Something* something = [Something alloc]; [something init]; [something dowork]; You are ignoring the instance returned from init If init decided to create or return something other than what you had asked for at the best, you re working with a poorly constructed instance at the worst, you re working with a object that may ve been released Objective-C 32
17 Do this Something* something = [[Something alloc] init]; [something dowork]; [something release]; or Something* something = [[[Something alloc] init] autorelease]; [something dowork]; You may check to ensure init did not return a nil Objective-C 33 Designated Initializer Each class has a designated initializer This is the most versatile initializer All other initializers call this designated initializer The designated initializer is the one that calls the super s designated initializer Each class should advertise its designated initializer (solely for the benefit of the person writing a subclass) Objective-C 34
18 Your Own Initializers Begin your initializers with the letters init Return type of init should be id Invoke your own designated initializer from your initializers Invoke base class s initializer from your designated initializer Set self to what the base initializer returns Initialize variables directly instead of using accessor methods If something failed, return a nil At point of failure (if you re setting nil, that is) release self Objective-C 35 init(s) with inheritance If your designated init method has different signature than the designated method of the base class, you must override the base s designated method in your class and route the call to your designated init method Objective-C 36
19 Writing Constructors Typically every instance has at least one constructor method. These methods start with the name init, but may be of any name following init and may take parameters Objective-C 37 Writing Constructors #import Person : NSObject (nonatomic, retain) NSString* (nonatomic, retain) NSString* NSInteger age; -(id) initwithfirstname: (NSString*) fname lastname: (NSString*) lname andage: (NSInteger) theage; -(id) initwithfirstname: (NSString*) fname lastname: (NSString*) Objective-C 38
20 Writing Constructors -(id) initwithfirstname: (NSString*) fname lastname: (NSString*) lname andage: (NSInteger) theage { if (self = [super init]) { self.firstname = fname; self.lastname = lname; self.age = theage; return self; -(id) initwithfirstname: (NSString*) fname lastname: (NSString*) lname { return [self initwithfirstname: fname lastname: lname andage: 1]; Objective-C 39 Using Constructors NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; Person* james = [[[Person alloc] lastname:@"bond" andage: 16] autorelease]; Person* bob = [[[Person alloc] autorelease]; [pool drain]; Objective-C 40
21 Type checking ismemberofclass function can help you with this. true only if instance is of specific type iskindofclass will tell you if instance is of type or of a derived type if ([james ismemberofclass: [Person class]] == YES) { printf("yes, James is of type Person\n"); if ([james iskindofclass: [NSObject class]] == YES) { printf("yes, james is of type NSObject or a derived type\n"); Objective-C 41 Selectors Objective-C allows you to get a pointer or handle to a method This is useful to register event handlers dynamically with UIView or controls This is also useful to delegate method execution An ability to pass functions around to other functions Objective-C 42
22 SEL A SEL is a special type that holds a pointer to the symbolic name of a method (after the compiler has converted the method name into an entry in the symbol table) You can ask the compiler to give you a handle to that entry using directive SEL mymethod If you don t know the method name at compile time (to make things real dynamic), you can get a SEL using NSSelectorFromString method NSStringFromSelector does the reverse for you Objective-C 43 Invoking Methods using SEL You can indirectly invoke a method using the selectors [instance withobject: anotherinstance]; is same as [instance.methodname: anotherinstance]; Objective-C 44
23 Using Selector Let s first define some methods -(void) drive: (NSNumber*) speed { printf("%s", [[NSString at speed %@\n", speed] UTF8String]); -(void) swim { printf("swimming\n"); -(void) run: (NSNumber*) distance { printf("%s", [[NSString distance %@\n", distance] UTF8String]); Objective-C 45 Using Selector NSNumber* speed = [NSNumber numberwithint: 100]; [james drive: speed]; // direct method call [james withobject: speed]; [james [james withobject: [NSNumber numberwithint: 5]]; SEL amethod = NSSelectorFromString(@"swim"); [james performselector: amethod]; Objective-C 46
24 Responds to a message? You can check if an instance responds to a message if([james { printf("can swim!\n"); Objective-C 47 Invoking a Method Later You can ask Objective-C to invoke a method, just a little, later using the afterdelay option This is quite convenience for you to handle touches/ tapping on the iphone You don t know if this is a single tap or first of a two tap You can ask the effect to take place in moments Quickly cancel that if you see the second tap using cancelpreviousperformrequestwithtarget Objective-C 48
25 Restricting Access You can restrict access to (which is the default) All members placed under a declaration have the same restriction until you change with another declaration Objective-C 49 Inheritance Use : to separate class from its super class Call base method using [super...] Objective-C 50
26 Categories Categories allow you to extend a class (even if you don t have the source code to that class) In one sense they re like partial classes in C# However, they re more like open classes in Ruby You write them ClassName (CategoryName) Objective-C 51 Categories #include <Foundation/Foundation.h> NSString (VenkatsStringUtil) -(NSString*) //StringUtil.m #import NSString(VenkatsStringUtil) -(NSString*) shout { return [self NSString* caution in main.m printf("%s\n", [[caution shout] UTF8String]); Objective-C 52
27 Protocols Protocols are like interfaces You can make a class conform to the methods of a protocol It can either adopt a protocol or inherits from a class that adopts a protocol Protocols can have required and optional methods! Adopting a ClassName : SuperClass <Protocol1, Protocol2,...> Objective-C 53 Protocols Drivable -(void) drive: (int) is the is the -(void) -(int) Objective-C 54
28 #import <Foundation/Foundation.h> #import "Drivable.h" Car : Car -(void) drive: (int) distance { printf("driving %d miles\n", distance); -(void) reverse { printf("reversing\n"); -(int) miles { return 0; Objective-C 55 Protocols Car* car = [[[Car alloc] init] autorelease]; [car drive: 10]; id<drivable> drivable = car; [drivable reverse]; You can get a reference to a protocol using the id<...> Objective-C 56
29 Protocols and Categories You can have a category of methods adopt a protocol, like ClassName (CategoryName) <protocol1, protocol2,...> Objective-C 57 Checking for Conformance You can check if an instance conforms to a protocol by calling conformstoprotocol: method if([car { printf("car is drivable\n"); Objective-C 58
30 References to Protocol You can store a explicit reference of type protocol like id<protocolname> ref Useful for type checking, ref can only refer to an instance that conforms to ProtocolName You can also write SomeClass<SomeProtocol> ref In this case ref can only refer to an instance of SomeClass or its derived class that conforms to SomeProtocol Objective-C 59 Collections You often have need to work with collections of objects There are three common collections you would use Arrays, Dictionaries, Sets These come in mutable and immutable flavors If you want to add (or remove) to a collection after you create it, use mutable flavors Objective-C 60
31 Using Arrays NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int ageoffriends[2] = {40, 43; printf("age of First friend %i\n", ageoffriends[0]); NSArray* friends = [[[NSArray nil] autorelease]; You re adding to the pool int count = [friends count]; printf("number of friends %d\n", count); NSArray* friends2 = nil]; Added to the pool for you printf("a friend %s\n", [[friends2 objectatindex: 0] UTF8String]); [pool drain]; Ordered sequence of objects NSArray is immutable, once you create it, you can no longer add or remove elements to it Objective-C 61 Iterating Arrays NSEnumerator* friendsenumerator = [friends objectenumerator]; id afriend; while ((afriend = [friendsenumerator nextobject])) { printf("%s\n", [afriend UTF8String]); int friendscount = [friends count]; for(int i = 0; i < friendscount; i++) { printf("%s\n", [[friends objectatindex: i] UTF8String]); for(nsstring* afriend in friends) { printf("%s\n", [afriend UTF8String]); Fast enumeration! Objective-C 62
32 Using Dictionary Associative key-value pairs NSDictionary* friends = nil] autorelease]; Key can t be null, you specify value and then key printf("joe is %s years old\n", [[friends UTF8String ]); //Iterating for(nsstring* afriend in friends) { printf("%s is %s years old\n", [afriend UTF8String], [[friends objectforkey: afriend] UTF8String]); Objective-C 63 Mutable vs. Immutable NSArray is immutable, you can t add elements to it or change it once it is created For mutable arrays, use NSMutableArray Similarly for mutable dictionary, you may use NSMutableDictionary Objective-C 64
33 @finally directives to handle to raise exceptions Very similar in construct to Java/C# exception handling Exception base class is NSException (but you could throw any type of exception - just like in C++) To re-throw an exception simply with no argument Objective-C 65 Exception Handling int madmethod(int number) [NSException upset" no reason" userinfo: nil]; int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] {!! (NSException* ex) {!! printf("something went wrong %s\n", [[ex reason] {!! printf("finally block...\n");! [pool drain]; return 0; Objective-C 66
34 #include vs. #import These help you to bring in, typically, header files They re similar except that import will ensure a file is never included more than once So, it is better to use #import instead of #include Objective-C 67 Forward Declaration While #import is quite helpful, there are times when you ll have trouble with cyclic dependency between classes or simply you want to defer #import to the implementation file In these cases, for forward declaration, SomeClass; For forward declaring protocols, ProtocolName; Objective-C 68
35 Memory Management On the iphone, you re responsible for garbage collection It can be very intimidating if you come from a JVM or a CLR background It is much less painful when compared to C++ But there is quite a bit of discipline to follow Objective-C 69 Memory Management Objective-C uses retain counting to keep track of objects life seems like COM all over again?! For most part you don t want to poke into retain counting, but you could! An object dies when its reference count goes to zero You have to take care of releasing objects you create using alloc or copy Objects you created without using alloc or copy are added to a NSAutoreleasePool you don t release these Your object should clean up objects it owns dealloc is a good place for this Objective-C 70
36 Three ways to Manage Mem alloc init use it Obj release it alloc init alloc init autorelease use it Obj its added release pool drain alloc init Create it using convenience init use it Obj its added release pool drain Objective-C 71 Autorelease pool Auto release pool is a managed object that holds references to objects When the pool is drained, it releases objects it holds Use drain and not release no pool (drain is a no-op in runtimes that provide automatic GC) You can have nested pools In iphone dev, you rarely create a pool its given for you Each invocation of event is managed by a pool Create a pool if you want quicker clean up (large objects in a loop) Objective-C 72
37 Memory Management Rules Some rules to follow Release objects you obtained by calling alloc, copy, etc. If you don t own it, don t release it If you store a pointer, make a copy or call retain Be mindful of object s life. If you obtain an object and cause its removal from a collection or remove its owner, the object may no longer be alive. To prevent this, retain while you use and release when done Objective-C 73 Memory Engine : NSObject { int _power; -(int) power; -(id) initwithpower: (int) thepower; +(id) enginewithpower: (int) You made power readonly You have provided a convenience constructor and a regular constructor Objective-C 74
38 Memory Engine -(int) power { return _power; -(id) initwithpower: (int) thepower { printf("engine created\n"); if (self = [super init]) { _power = thepower; return self; - (id)init { return [self initwithpower: 10]; +(id) enginewithpower: (int) thepower { return [[[Engine alloc] initwithpower: thepower] autorelease]; Convenience constructor adds instance to the pool - (void)dealloc { printf("engine deallocated\n"); [super dealloc]; invoke your designated constructor from the init method Objective-C 75 Memory Management #import Car : NSObject { int _year; Engine* _engine; -(Engine*) engine; -(void) setengine: (Engine*) engine; -(int) year; -(id) initwithyear: (int) year engine: (Engine*) engine; +(id) carwithyear: (int) year engine: (Engine*) Objective-C 76
39 Memory Car -(Engine*) engine { return _engine; -(void) setengine: (Engine*) engine { [_engine release]; [engine retain]; _engine = engine; // or you could make a copy -(int) year { return _year; Your setengine should take care of cleanup. It should also call retain to take ownership of the engine. Objective-C 77 Memory Management -(id) initwithyear: (int) year engine: (Engine*) engine { printf("car created\n"); if (self = [super init]) { _year = year; [engine retain]; _engine = engine; Remember to call retain. return self; -(id) init [[NSException alloc] construction" year and engine" userinfo:nil]; +(id) carwithyear: (int) year engine: (Engine*) engine { return [[[Car alloc] initwithyear: year engine: engine] autorelease]; Objective-C 78
40 Memory Management - (void)dealloc { printf("car deallocated\n"); [_engine release]; [super dealloc]; Remember to Objective-C 79 Memory Management Car* createcar(int year, int enginepower) { Engine* engine = [[[Engine alloc] initwithpower: enginepower] autorelease]; Car* car = [Car carwithyear: year engine: engine]; return car; int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; printf("\n"); Car* car1 = createcar(2010, 20); Car* car2 = createcar(2010, 30); Engine* engine = [Engine enginewithpower: 25]; [car2 setengine: engine]; printf("%d %d\n", [car1 year], [[car1 engine] power]); printf("%d %d\n", [car2 year], [[car2 engine] power]); [pool drain]; return 0; # of objects created should be equal to # destroyed. Objective-C 80
41 Easing Pain With Properties You have to remember to call retain and release on objects Your setter gets complicated because of this You can ease the pain using properties The generated setter knows when and what to release When you call set, it releases existing object and adds retain on the new one Objective-C 81 Easing Pain With Engine : NSObject (readonly) int power; -(id) initwithpower: (int) thepower; +(id) enginewithpower: power; Property make life a bit easy here. -(id) initwithpower: (int) thepower { printf("engine created\n"); if (self = [super init]) { self->power = thepower; //Way to set the readonly property return self;... Objective-C 82
42 @synthesize engine; Easing Pain With Car : NSObject (nonatomic, retain) Engine* (readonly) int year; -(id) initwithyear: (int) year engine: (Engine*) engine; +(id) carwithyear: (int) year engine: (Engine*) if (self = [super init]) { self->year = theyear; self.engine = theengine; return self; Property make life a lot easier here. -(id) initwithyear: (int) theyear engine: (Engine*) theengine { printf("car created\n"); No need to write getters and setters - (void)dealloc { printf("car deallocated\n"); self.engine = nil; [super dealloc]; Objective-C 83 Easing Pain With Properties Car* createcar(int year, int enginepower) { Engine* engine = [[[Engine alloc] initwithpower: enginepower] autorelease]; Usage of these classes does not change Car* car = [Car carwithyear: year engine: engine]; return car; int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; printf("\n"); Car* car1 = createcar(2010, 20); Car* car2 = createcar(2010, 30); Engine* engine = [Engine enginewithpower: 25]; [car2 setengine: engine]; printf("%d %d\n", [car1 year], [[car1 engine] power]); printf("%d %d\n", [car2 year], [[car2 engine] power]); [pool drain]; return 0; Objective-C 84
43 Blocks in Objective-C Represents a chunk of code They're like closures or function values in functional languages They respond to NSObject methods Objective-C 85 Declaring a Block You use the symbol ^ to indicate you re declaring a block You can create an anonymous function You can assign it to a variable (or handle) if you like Objective-C 86
44 Using A Block NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSArray* values = [NSArray arraywithobjects: [NSNumber numberwithint:1], [NSNumber numberwithint:2], [NSNumber numberwithint:3], [NSNumber numberwithint:4], nil]; [values enumerateobjectsusingblock: ^(id obj, NSUInteger number, BOOL* breakout) { printf("number at index %lu is %d\n", number, [obj intvalue]); ]; [pool drain]; Objective-C 87 Block Can Reach Out int factor = 2; [values enumerateobjectsusingblock: ^(id obj, NSUInteger number, BOOL* breakout) { printf("double of number at index %lu is %d\n", number, [obj intvalue] * factor); ]; You re able to access factor from within the block. block makes a copy of the variable it reaches out to. You can t change the outside variable... unless you mark them with block Objective-C 88
45 block block int total = 0; [values enumerateobjectsusingblock: ^(id obj, NSUInteger number, BOOL* breakout) { total += [obj intvalue]; ]; printf("total of values is %d\n", total); If you want to modify an outside variable from within a block, you have to annotate it with a block Objective-C 89 Thank You! Venkat Subramaniam [email protected] twitter: venkat_s
INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011
INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011 1 Goals of the Lecture Present an introduction to Objective-C 2.0 Coverage of the language will be INCOMPLETE
iphone Objective-C Exercises
iphone Objective-C Exercises About These Exercises The only prerequisite for these exercises is an eagerness to learn. While it helps to have a background in object-oriented programming, that is not a
Key-Value Coding Programming Guide
Key-Value Coding Programming Guide Contents Introduction 6 Organization of This Document 6 See Also 7 What Is Key-Value Coding? 8 Key-Value Coding and Scripting 8 Using Key-Value Coding to Simplify Your
ios Dev Crib Sheet In the Shadow of C
ios Dev Crib Sheet As you dive into the deep end of the ios development pool, the first thing to remember is that the mother ship holds the authoritative documentation for this endeavor http://developer.apple.com/ios
MA-WA1920: Enterprise iphone and ipad Programming
MA-WA1920: Enterprise iphone and ipad Programming Description This 5 day iphone training course teaches application development for the ios platform. It covers iphone, ipad and ipod Touch devices. This
Objective-C Tutorial
Objective-C Tutorial OBJECTIVE-C TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Objective-c tutorial Objective-C is a general-purpose, object-oriented programming
Objective-C and Cocoa User Guide and Reference Manual. Version 5.0
Objective-C and Cocoa User Guide and Reference Manual Version 5.0 Copyright and Trademarks LispWorks Objective-C and Cocoa Interface User Guide and Reference Manual Version 5.0 March 2006 Copyright 2006
Introduction to iphone Development
Introduction to iphone Development Introduction to iphone Development Contents Task 1 2 3 4 Application Runtime Core Architecture and Life-cycles What s in a bundle? The resources in an app bundle Customizing
Object Oriented Programming and the Objective-C Programming Language 1.0. (Retired Document)
Object Oriented Programming and the Objective-C Programming Language 1.0 (Retired Document) Contents Introduction to The Objective-C Programming Language 1.0 7 Who Should Read This Document 7 Organization
Using the Caché Objective-C Binding
Using the Caché Objective-C Binding Version 2014.1 25 March 2014 InterSystems Corporation 1 Memorial Drive Cambridge MA 02142 www.intersystems.com Using the Caché Objective-C Binding Caché Version 2014.1
Creating a Custom Class in Xcode
Creating a Custom Class in Xcode By Mark Mudri March 28, 2014 Executive Summary: Making an ios application requires the use of Xcode, an integrated development environment (IDE) developed by Apple. Within
Objective C and iphone App
Objective C and iphone App 6 Months Course Description: Understanding the Objective-C programming language is critical to becoming a successful iphone developer. This class is designed to teach you a solid
Praktikum Entwicklung von Mediensystemen mit
Praktikum Entwicklung von Mediensystemen mit Wintersemester 2013/2014 Christian Weiß, Dr. Alexander De Luca Today Organization Introduction to ios programming Hello World Assignment 1 2 Organization 6
An Introduction to Modern Software Development Tools Creating A Simple GUI-Based Tool Appleʼs XCode Version 3.2.6
1 2 3 4 An Introduction to Modern Software Development Tools Creating A Simple GUI-Based Tool Appleʼs XCode Version 3.2.6 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Charles J. Ammon / Penn State August, 2011
Java Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
INTRODUCTION TO IOS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 13 02/22/2011
INTRODUCTION TO IOS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 13 02/22/2011 1 Goals of the Lecture Present an introduction to ios Program Coverage of the language will be INCOMPLETE We
Object Oriented Software Design II
Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February
ios Dev Fest Research Network Operations Center Thursday, February 7, 13
ios Dev Fest Research Network Operations Center Outline http://goo.gl/02blw Getting Started With App Development Setup Developer Environment Setup Certificates and Provisioning Deploying App To Device
ios Development Tutorial Nikhil Yadav CSE 40816/60816: Pervasive Health 09/09/2011
ios Development Tutorial Nikhil Yadav CSE 40816/60816: Pervasive Health 09/09/2011 Healthcare iphone apps Various apps for the iphone available Diagnostic, Diet and Nutrition, Fitness, Emotional Well-being
09336863931 : provid.ir
provid.ir 09336863931 : NET Architecture Core CSharp o Variable o Variable Scope o Type Inference o Namespaces o Preprocessor Directives Statements and Flow of Execution o If Statement o Switch Statement
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Bonus ChapteR. Objective-C
Bonus ChapteR Objective-C If you want to develop native ios applications, you must learn Objective-C. For many, this is an intimidating task with a steep learning curve. Objective-C mixes a wide range
Pemrograman Dasar. Basic Elements Of Java
Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle
Praktikum Entwicklung von Mediensystemen mit ios
Praktikum Entwicklung von Mediensystemen mit ios SS 2011 Michael Rohs [email protected] MHCI Lab, LMU München Timeline Date Topic/Activity 5.5.2011 Introduction and Overview of the ios Platform 12.5.2011
NSPersistentDocument Core Data Tutorial for Mac OS X v10.4. (Retired Document)
NSPersistentDocument Core Data Tutorial for Mac OS X v10.4. (Retired Document) Contents Introduction to NSPersistentDocument Core Data Tutorial for Mac OS X v10.4 8 Who Should Read This Document 8 Organization
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1
Event Driven Simulation in NS2 Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1 Outline Recap: Discrete Event v.s. Time Driven Events and Handlers The Scheduler
Fundamentals of Java Programming
Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors
The C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
Praktikum Entwicklung von Mediensystemen mit ios
Praktikum Entwicklung von Mediensystemen mit ios SS 2011 Michael Rohs [email protected] MHCI Lab, LMU München Today Schedule Organization Introduction to ios Exercise 1 2 Schedule Phase 1 Individual
The programming language C. sws1 1
The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,
Getting Started with the Internet Communications Engine
Getting Started with the Internet Communications Engine David Vriezen April 7, 2014 Contents 1 Introduction 2 2 About Ice 2 2.1 Proxies................................. 2 3 Setting Up ICE 2 4 Slices 2
CORBA Programming with TAOX11. The C++11 CORBA Implementation
CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy
Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:
Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of
Java Programming Fundamentals
Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few
Glossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
Objective-C Internals
Objective-C Internals André Pang Realmac Software Nice license plate, eh? 1 In this talk, we peek under the hood and have a look at Objective-C s engine: how objects are represented in memory, and how
Crash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
An Incomplete C++ Primer. University of Wyoming MA 5310
An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages
Common Lisp ObjectiveC Interface
Common Lisp ObjectiveC Interface Documentation for the Common Lisp Objective C Interface, version 1.0. Copyright c 2007 Luigi Panzeri Copying and distribution of this file, with or without modification,
PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON
PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London
CS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
Objectif. Participant. Prérequis. Remarque. Programme. C# 3.0 Programming in the.net Framework. 1. Introduction to the.
Objectif This six-day instructor-led course provides students with the knowledge and skills to develop applications in the.net 3.5 using the C# 3.0 programming language. C# is one of the most popular programming
Java Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
Assignment I Walkthrough
Assignment I Walkthrough Objective Reproduce the demonstration (building a calculator) given in class. Goals 1. Downloading and installing the ios4 SDK. 2. Creating a new project in Xcode. 3. Defining
Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)
Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
Chapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
Java (12 Weeks) Introduction to Java Programming Language
Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short
Habanero Extreme Scale Software Research Project
Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead
Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C
Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner
java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources
C++ Programming Language
C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract
Chapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named
C++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
Development of Computer Graphics and Digital Image Processing on the iphone Luciano Fagundes ([email protected].
Development of Computer Graphics and Digital Image Processing on the iphone Luciano Fagundes ([email protected]) Rafael Santos ([email protected]) Motivation ios Devices Dev Basics From Concept
Programming Languages CIS 443
Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception
Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar
Lexical Analysis and Scanning Honors Compilers Feb 5 th 2001 Robert Dewar The Input Read string input Might be sequence of characters (Unix) Might be sequence of lines (VMS) Character set ASCII ISO Latin-1
CyberSource ios SDK for Apple Pay
Title Page CyberSource ios SDK for Apple Pay Developer Guide March 2015 CyberSource Corporation HQ P.O. Box 8999 San Francisco, CA 94128-8999 Phone: 800-530-9095 CyberSource Contact Information For general
This documentation is made available before final release and is subject to change without notice and comes with no warranty express or implied.
Hyperloop for ios Programming Guide This documentation is made available before final release and is subject to change without notice and comes with no warranty express or implied. Requirements You ll
Module 816. File Management in C. M. Campbell 1993 Deakin University
M. Campbell 1993 Deakin University Aim Learning objectives Content After working through this module you should be able to create C programs that create an use both text and binary files. After working
How to create/avoid memory leak in Java and.net? Venkat Subramaniam [email protected] http://www.durasoftcorp.com
How to create/avoid memory leak in Java and.net? Venkat Subramaniam [email protected] http://www.durasoftcorp.com Abstract Java and.net provide run time environment for managed code, and Automatic
CS193j, Stanford Handout #10 OOP 3
CS193j, Stanford Handout #10 Summer, 2003 Manu Kumar OOP 3 Abstract Superclass Factor Common Code Up Several related classes with overlapping code Factor common code up into a common superclass Examples
www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk
CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling
Java programming for C/C++ developers
Skill Level: Introductory Scott Stricker ([email protected]) Developer IBM 28 May 2002 This tutorial uses working code examples to introduce the Java language to C and C++ programmers. Section 1. Getting
University of Twente. A simulation of the Java Virtual Machine using graph grammars
University of Twente Department of Computer Science A simulation of the Java Virtual Machine using graph grammars Master of Science thesis M. R. Arends, November 2003 A simulation of the Java Virtual Machine
Chapter 1 Fundamentals of Java Programming
Chapter 1 Fundamentals of Java Programming Computers and Computer Programming Writing and Executing a Java Program Elements of a Java Program Features of Java Accessing the Classes and Class Members The
Semantic Analysis: Types and Type Checking
Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors
Java Programming Language
Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and
1 The Java Virtual Machine
1 The Java Virtual Machine About the Spec Format This document describes the Java virtual machine and the instruction set. In this introduction, each component of the machine is briefly described. This
Lecture 18-19 Data Types and Types of a Language
Lecture 18-19 Data Types and Types of a Language April 29, 2014 Data Types and Types of a Language Data, Data Types and Types Type: Generalities Type Systems and Type Safety Type Equivalence, Coercion
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions
Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment
WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.
WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25
Comp151. Definitions & Declarations
Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const
Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages. Corky Cartwright Swarat Chaudhuri November 30, 20111
Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages Corky Cartwright Swarat Chaudhuri November 30, 20111 Overview I In OO languages, data values (except for designated non-oo
CS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper
D06 PROGRAMMING with JAVA. Ch3 Implementing Classes
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch3 Implementing Classes PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com,
Introduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Programs and Methods Christopher Simpkins [email protected] CS 1331 (Georgia Tech) Programs and Methods 1 / 8 The Anatomy of a Java Program It is customary
CSC230 Getting Starting in C. Tyler Bletsch
CSC230 Getting Starting in C Tyler Bletsch What is C? The language of UNIX Procedural language (no classes) Low-level access to memory Easy to map to machine language Not much run-time stuff needed Surprisingly
ECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Introduction to Electrical and Computer Engineering II Lecture 1 Course Overview Welcome! What is this class about? Java programming somewhat software somewhat
Curriculum Map. Discipline: Computer Science Course: C++
Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code
Introduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
Tutorial: Getting Started
9 Tutorial: Getting Started INFRASTRUCTURE A MAKEFILE PLAIN HELLO WORLD APERIODIC HELLO WORLD PERIODIC HELLO WORLD WATCH THOSE REAL-TIME PRIORITIES THEY ARE SERIOUS SUMMARY Getting started with a new platform
AP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
CISC 181 Project 3 Designing Classes for Bank Accounts
CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on
17. November 2015. Übung 1 mit Swift. Architektur verteilter Anwendungen. Thorsten Kober Head Solutions ios/os X, SemVox GmbH
17. November 2015 Übung 1 mit Swift Architektur verteilter Anwendungen Thorsten Kober Head Solutions ios/os X, SemVox GmbH Überblick 1 Einführung 2 Typen, Optionals und Pattern Matching 3 Speichermanagement
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
#820 Computer Programming 1A
Computer Programming I Levels: 10-12 Units of Credit: 1.0 CIP Code: 11.0201 Core Code: 35-02-00-00-030 Prerequisites: Secondary Math I, Keyboarding Proficiency, Computer Literacy requirement Semester 1
