Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

iOS_Course_5

541 views

Published on

iOS Course lection 5.
Classes, Methods, types.

Published in: Software
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

iOS_Course_5

  1. 1. iOS: Sviluppo App iPhone & iPad Dario Pizzuto 1
  2. 2. Objective-C 2
  3. 3. Objective-C 3 Argomenti! • Introduzione! • Linguaggio! • Tipi di base! • Classi e Oggetti
  4. 4. Introduzione 4
  5. 5. Objective-C • Linguaggio di programmazione ad oggetti! • La base è il linguaggio C! • Objective-C è un sovra-insieme di C 5
  6. 6. Objective-C • Sviluppato negli anni ’80! • Si diffonde grazie all’uso nel framework OpenStep della NeXT! • NeXT contribuisce a rendere fruibile il linguaggio dal compilatore GCC 6
  7. 7. Objective-C • ARC (Automatic Reference Counting)! • Multithread! • Exceptions! • Frameworks 7
  8. 8. Tipi di base 8
  9. 9. Objective-C 9 Numeri Interi! • Short! • Int! • long! • Unsigned ! • NSInteger ! ‣ Architecture independent 32-64bit
  10. 10. Objective-C Numeri Reali! • float! • double! • long double! • CGFloat (CoreGraphics float)! ‣ Architecture independent 32-64bit 10
  11. 11. Objective-C Stringhe! • Classi per manipolazione stringhe! • NSString! ‣ Immutable! • NSMutableString! ‣ Mutable! @”Questa è una stringa in Objective-C” 11
  12. 12. Objective-C 12 Booleani! • BOOL! ‣ YES / NO! !
  13. 13. Objective-C Struct! • Insieme di variabili legate da un nesso 13 logico! struct nameStruct {! int x;! int y;! };!
  14. 14. Objective-C Union! • Definisce un’unione logica di variabili! • Uso esclusivo di una tra quelle inserite nella 14 union! union nameUnion {! int x;! float y;! char a;! };!
  15. 15. Objective-C Typedef! • Permette di definire un nuovo tipo di 15 dato! typedef int size;! ! • size è un nuovo tipo basato su int
  16. 16. Objective-C Enum! • Permette di definire dati che rientrano in un determinato insieme! 16 enum Semi{! CUORI = 1,! QUADRI,! FIORI,! PICCHE! };!
  17. 17. Objective-C Puntatori! • Fondamentali per l’uso degli oggetti di Objective-C! • Si identifica con * (asterisco)! • Il puntatore rappresenta la variabile che contiene l’indirizzo di memoria della variabile da noi definita! NSString *name = @”Dario”;! • name contiene l’Indirizzo di memoria 0x1000! • L’indirizzo 0x1000 contiene “Dario” 17
  18. 18. Objective-C Tipo id! • Rappresenta un oggetto ! • Non è NSString, NSInteger! • Oggetto non tipizzato! id name;! 18
  19. 19. Objective-C Cast! • Identifica il passaggio di tipo! • Es.! 19 ✓double a int! double a = 12.3;! int i;! i = (int) a;! • i adesso vale 12!
  20. 20. Objective-C Operatori aritmetici! Operatore Esempio ! Significato + a + b Somma a e b ! - a - b Differenza tra a e b / a / b ! Divide a per b * a * b ! Moltiplica a per b % a % b Resto della divisione tra a e b ! += a += b Assegna ad a la somma di a e b -= a -= b Assegna ! ad a il risultato di a - b /= a /= b Assegna ad a il risultato di a / b *= a *= b Assegna ad a il risultato di a * b %= a %= b Assegna ad a il risultato di a % b 20
  21. 21. Objective-C Incremento e decremento! • Diversi modi per incrementare o decrementare una variabile! ✓i++; ++i;! ✓ j--; --j;! 21
  22. 22. Objective-C Operatori di confronto! ! Operatore Esempio Significato ! < a < b Inferiore di ! <= a <= b Inferiore o uguale a ! > a > b Maggiore di ! >= a >= b Maggiore o uguale a ! != a != b Diverso da == a == b Uguale a 22
  23. 23. Objective-C Operatori logici! ! Operatore Esempio Significato ! ! ! !a Negazione logica ! ! && a && b AND logico ! || a || b OR logico 23
  24. 24. Condizioni 24
  25. 25. Objective-C Condizioni! • Permettono di eseguire operazioni in base a delle condizioni! • Possono essere annidate! 25
  26. 26. Objective-C Salto condizionale! • Valutare una condizione ed eseguire delle istruzioni di cnseguenza! if(espressione){! 26 istruzioni;! }! [ else{! istruzioni; ! } ]!
  27. 27. Objective-C Salto condizionale esempio! if(a > b){! NSLog(@”a maggiore di b”);! 27 }! else{! NSLog(@”b maggiore di a”);! } !
  28. 28. Objective-C Scelta multipla! • Eseguire blocchi di istruzioni in abse al valore di una variabile! switch(espressione) {! 28 case cost1:! istruzioni;! case cost2:! istruzioni;! [ default:! istruzioni; ]! }
  29. 29. Objective-C 29 Scelta multipla esempio! switch(seme) {! case 1:! NSLog(@”Cuori”);! break;! case 2:! NSLog(@”Quadri”);! break;! case 3:! NSLog(@”Fiori”);! break! case 4:! NSLog(@”Picche”);! break;! }
  30. 30. Let’s Code 30
  31. 31. Objective-C Let’s Code! ✦Implementiamo una condizione che ci permetta di definire se un numero è pari o dispari 31
  32. 32. Iterazioni 32
  33. 33. Objective-C Iterazioni! • Strutture fondamentali che permettono di eseguire più volte lo stesso gruppo di istruzioni! • Meglio conosciuti come “Cicli”! 33
  34. 34. Objective-C Ciclo while! • Esegue un gruppo di istruzioni finché l’espressione è valida! while(espressione) {! 34 istruzioni;! }
  35. 35. Objective-C Ciclo do! • Valuta l’espressione di validazione alla fine del primo ciclo! • Esegue almeno una volta le istruzioni! do {! istruzioni;! } while(espressione) 35
  36. 36. Objective-C Ciclo for! • Uno dei costrutti più comuni e versatili! for(inizializzazione; controllo; incremento) {! 36 istruzioni;! }! • inizializzazione: imposta le variabili di controllo! • controllo: valuta se il ciclo deve interrompersi! • incremento: assegna alle variabili inizializzate i nuovi valori
  37. 37. Objective-C Ciclo for esempio! for(int i =0; i < 4; i++) {! NSLog(@”%i ”,i);! 37 }! ! Output: 0 1 2 3
  38. 38. Objective-C Ciclo for veloce! • Esegue un’iterazione sugli oggetti di una collezione! NSArray *names = @[@”Mario”, @”Luca”, @”Antonio”]! for(NSString *name in names) {! NSLog(@”%@ ”,name);! }! ! Output: Mario Luca Antonio 38
  39. 39. Objective-C Interrompere un ciclo! • È possibile interrompere il ciclo! ! break;! ! • In cicli annidati, viene interrotto solo il 39 ciclo interessato
  40. 40. Let’s Code 40
  41. 41. Objective-C Let’s Code! ✦Attraverso uno dei loop menzionati, implementare l’output a console dei numeri da 0 a 100 41
  42. 42. Classi ed Oggetti 42
  43. 43. Objective-C Classe! • Costrutto utilizzato per creare oggetti in fase di esecuzione! • La classe definisce l’organizzazione logica! • Es.! ✓ Auto! ✓ Animale 43
  44. 44. Objective-C Classe! • Si rappresenta una classe attraverso 2 files! ✓ file di interfaccia: *.h! ✓ file di implementazione: *.m! 44
  45. 45. Objective-C Interfaccia! • Costituisce la definizione della classe! @interface ClassName [: Superclass] {! 45 [properties]! [methods]! }!
  46. 46. Objective-C Interfaccia! • ClassName: nome da assegnare alla classe! • Superclass: classe da cui derivare, se non viene indicata NSObject di default! • properties: attributi della classe! • methods: metodi della classe! 46
  47. 47. Objective-C Implementazione! • Costituisce l’implementazione della classe! @implementation ClassName : Superclass {! 47 [iVar]! }! [methods implementation]! }
  48. 48. Objective-C Implementazione! • iVar: variabili di istanza! ❖Possibile definire iVar nell’interfaccia ? Si ma sconsigliato. Viola l’incapsulamento! • Methods implementation: implementazione dei metodi definiti nell’interfaccia! • Xcode ci avverte se vi sono dei metodi non 48 implementati !
  49. 49. Objective-C Interfaccia DPPPersona.h Implementazione DPPPersona.m 49
  50. 50. Variabili e Metodi 50
  51. 51. Objective-C Variabili! • Dichiarare una variabile per riga! ! NSString *name;! NSArray *names;! int age;! 51
  52. 52. Objective-C Definizione di metodo! [ + ı - ] (tipo di ritorno) methodName [parametro1:(tipo1)parametro1 parametro2: (tipo2)parametro2] {! 52 istruzioni;! return valore;! }
  53. 53. Objective-C Metodi! • + ı - : rappresentano il tipo di metodo (classe o istanza)! • tipo di ritorno: il tipo di dato che ritorna il metodo! • methodName: nome metodo (notare 53 CamelCase)!
  54. 54. Objective-C Metodi di Classe! • Metodi che possono essere invocati senza istanziare l’oggetto! • Es.! ✓+ (id) alloc! ✓+ (id) sharedInstance! 54
  55. 55. Objective-C Metodi di Istanza! • Metodi che possono essere invocati su un’istanza specifica! • Es.! ✓- (void) setName! ✓- (int) countItems! 55
  56. 56. Objective-C Esempio Interfaccia DPPPersona! 56 ! ! ! ! ! ! !
  57. 57. Objective-C Esempio Implementazione DPPPersona! 57 ! ! ! ! ! ! !
  58. 58. Self 58
  59. 59. Objective-C Self! • Parola chiave che identifica “se stesso”! • La classe stessa !! • È possibile accedere alle variabili di istanza attraverso l’uso di self! 59
  60. 60. Objective-C 60 Uso di self! ! ! ! ! !
  61. 61. Super 61
  62. 62. Objective-C Super! • Parola chiave che identifica la Superclasse! • Se invoco un metodo con super, il runtime ricerca quel metodo nella superclasse! • Fondamentale quando creiamo delle 62 sottoclassi!
  63. 63. Objective-C 63 Esempio super! ! ! ! ! !
  64. 64. Usare una classe 64
  65. 65. Objective-C Istanziazione! • Per utilizzare una oggetto bisogna averlo istanziato! • L’istanziazione crea l’oggetto della classe! • Se la classe non viene istanziata, l’oggetto non può essere usato! 65
  66. 66. Objective-C Istanziazione! • Ci sono dei metodi di default che istanziano un oggetto! ✓[[DPPPersona alloc] init];! ✓[DPPPersona new];! 66
  67. 67. Objective-C Istanziazione custom! • Possiamo definire un nostro metodo di istanziazione! • Override metodo init! - (instancetype) init {! 67 if(self){! _nome = @”Default”;! _cognome = @”Default”! }! return self;! }
  68. 68. Objective-C Istanziazione! • Il metodo crea un’istanza della classe e ritorna se stessa! • Possibilità di creare metodi di “init” con parametri! ✓ - (instancetype) initWithNome: (NSString*)nome;! 68 !
  69. 69. Creare una classe da Xcode 69
  70. 70. Objective-C 70 Nuova classe! • File -> New -> File! ! ! ! ! !
  71. 71. Objective-C 71 Nuova classe! ! ! ! ! ! !
  72. 72. Objective-C 72 Nuova classe! ! ! ! ! ! ! Class Nome della classe Subclass Subclass da cui derivare
  73. 73. Objective-C ! Ulteriori approfondimenti! GNU Compiler Collection! Defining Classes! 73 !
  74. 74. Domande ? 74
  75. 75. Let’s Code 75
  76. 76. Objective-C Let’s Code! ✦Implementare una classe che contenga almeno 3 variabili di istanza di tipo diverso e 2 metodi 76

×