SlideShare a Scribd company logo
1 of 16
Download to read offline
Computer Science Large Practical:

                                     Arrays in Objective-C

                                               Stephen Gilmore

                                               School of Informatics


                                          Friday 2nd November, 2012




Stephen Gilmore (School of Informatics)      Computer Science Large Practical   Friday 2nd November, 2012   1 / 16
Experience report




         The Desktop Team, in the University’s Information Services
         department have asked for feedback from you regarding your
         experiences (good or bad!) with Xcode in the Main Library IS Open
         Access Lab.
         This will help inform their plans for future academic years.
         What has been your experience?




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   2 / 16
Programming with arrays in Objective-C




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   3 / 16
Inspecting an array




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   4 / 16
The XML representation




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   5 / 16
Sorting an array




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   6 / 16
The sorted array




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   7 / 16
The output in the console




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   8 / 16
Everything OK? What about “Build and Analyze”?




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   9 / 16
Handling arrays (1/2)
 #import <Foundation/Foundation.h>
 int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]
        init];

       NSLog(@"Hello, arrays!");

       NSArray * myArray = [[NSArray alloc]
          initWithObjects:@"foo",@"bar",@"baz",nil];

       for(NSString * myStr in myArray) {
          NSLog(@"-- %@", myStr);
       }

       [myArray writeToFile:@"myArray.plist" atomically:YES];

Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   10 / 16
Handling arrays (2/2)

       NSArray *sortedArray = [myArray
          sortedArrayUsingSelector:@selector(
           caseInsensitiveCompare:)];

       [sortedArray writeToFile:@"sortedArray.plist"
           atomically:YES];

       for(NSString * myStr in sortedArray) {
          NSLog(@"---- %@", myStr);
       }

       [pool drain];
       return 0;
 }

Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   11 / 16
Object allocation and arrays


         Arrays in Objective-C are not generic arrays: they can contain
         different kinds of objects.
         The nil value at the end is a terminator, signalling the end of the
         array.
         You can release an object as soon as you add it to an array because
         the array allocates its own memory for the object by calling retain on
         all objects which are added to it.
         arrayWithObjects auto releases from memory so you do not have
         to release the array yourself.
         If we replace [NSArray alloc] initWithObjects with
         arrayWithObjects then this should solve our memory leak.



Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   12 / 16
“Build and Analyze” finds no potential leaks now




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   13 / 16
Mutable arrays




         NSArray objects are not mutable so we cannot update their contents.
         To have an array which we can update we should use
         NSMutableArray.




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   14 / 16
Declaring and using mutable arrays




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   15 / 16
Output from the program




Stephen Gilmore (School of Informatics)   Computer Science Large Practical   Friday 2nd November, 2012   16 / 16

More Related Content

What's hot

Domain Specific Language Design
Domain Specific Language DesignDomain Specific Language Design
Domain Specific Language DesignMarkus Voelter
 
Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo designConfiz
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?Colin Riley
 
Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeValerio Maggio
 
Object Oriented Programming : A Brief History and its significance
Object Oriented Programming : A Brief History and its significanceObject Oriented Programming : A Brief History and its significance
Object Oriented Programming : A Brief History and its significanceGajesh Bhat
 
Getting started with Xcode
Getting started with XcodeGetting started with Xcode
Getting started with XcodeStephen Gilmore
 
LectureNotes - RCOS Final Talk
LectureNotes - RCOS Final TalkLectureNotes - RCOS Final Talk
LectureNotes - RCOS Final TalkCalcAndCoffee
 
Design pattern - Software Engineering
Design pattern - Software EngineeringDesign pattern - Software Engineering
Design pattern - Software EngineeringNadimozzaman Pappo
 

What's hot (20)

Code Smell
Code SmellCode Smell
Code Smell
 
Code Smells
Code SmellsCode Smells
Code Smells
 
BDD Primer
BDD PrimerBDD Primer
BDD Primer
 
Domain Specific Language Design
Domain Specific Language DesignDomain Specific Language Design
Domain Specific Language Design
 
Ch06lect1 ud
Ch06lect1 udCh06lect1 ud
Ch06lect1 ud
 
Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo design
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?
 
Ch10lect1 ud
Ch10lect1 udCh10lect1 ud
Ch10lect1 ud
 
Clean code-v2.2
Clean code-v2.2Clean code-v2.2
Clean code-v2.2
 
Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing code
 
Ch11lect1 ud
Ch11lect1 udCh11lect1 ud
Ch11lect1 ud
 
Ch07lect1 ud
Ch07lect1 udCh07lect1 ud
Ch07lect1 ud
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Ch03lect1 ud
Ch03lect1 udCh03lect1 ud
Ch03lect1 ud
 
Object Oriented Programming : A Brief History and its significance
Object Oriented Programming : A Brief History and its significanceObject Oriented Programming : A Brief History and its significance
Object Oriented Programming : A Brief History and its significance
 
Cd2Alloy
Cd2AlloyCd2Alloy
Cd2Alloy
 
Getting started with Xcode
Getting started with XcodeGetting started with Xcode
Getting started with Xcode
 
LectureNotes - RCOS Final Talk
LectureNotes - RCOS Final TalkLectureNotes - RCOS Final Talk
LectureNotes - RCOS Final Talk
 
Ch05lect1 ud
Ch05lect1 udCh05lect1 ud
Ch05lect1 ud
 
Design pattern - Software Engineering
Design pattern - Software EngineeringDesign pattern - Software Engineering
Design pattern - Software Engineering
 

Viewers also liked

SELP: Debugging, AVDs and Manifests
SELP: Debugging, AVDs and ManifestsSELP: Debugging, AVDs and Manifests
SELP: Debugging, AVDs and ManifestsStephen Gilmore
 
Working with databases in Android
Working with databases in AndroidWorking with databases in Android
Working with databases in AndroidStephen Gilmore
 
Hacker Halted 2014 - Reverse Engineering the Android OS
Hacker Halted 2014 - Reverse Engineering the Android OSHacker Halted 2014 - Reverse Engineering the Android OS
Hacker Halted 2014 - Reverse Engineering the Android OSEC-Council
 
My Final year project on Android app development
My Final year project on Android app developmentMy Final year project on Android app development
My Final year project on Android app developmentrahulkumargiri
 
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsSteelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsTom Keetch
 
Toll app - Android project
Toll app - Android projectToll app - Android project
Toll app - Android projectArun prasath
 
UseCase is a DIALOG---NOT a PROCESS
UseCase is a DIALOG---NOT a PROCESSUseCase is a DIALOG---NOT a PROCESS
UseCase is a DIALOG---NOT a PROCESSPutcha Narasimham
 
Activity diagram railway reservation system
Activity diagram railway reservation systemActivity diagram railway reservation system
Activity diagram railway reservation systemmuthumeenakshim
 
Payroll and attendance system
Payroll and attendance system Payroll and attendance system
Payroll and attendance system Moses Nkrumah
 
Usecase diagram railway reservation system
Usecase diagram railway reservation systemUsecase diagram railway reservation system
Usecase diagram railway reservation systemmuthumeenakshim
 
Android seminar-presentation
Android seminar-presentationAndroid seminar-presentation
Android seminar-presentationconnectshilpa
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering pptshruths2890
 

Viewers also liked (14)

Android overview
Android overviewAndroid overview
Android overview
 
SELP: Debugging, AVDs and Manifests
SELP: Debugging, AVDs and ManifestsSELP: Debugging, AVDs and Manifests
SELP: Debugging, AVDs and Manifests
 
Working with databases in Android
Working with databases in AndroidWorking with databases in Android
Working with databases in Android
 
Hacker Halted 2014 - Reverse Engineering the Android OS
Hacker Halted 2014 - Reverse Engineering the Android OSHacker Halted 2014 - Reverse Engineering the Android OS
Hacker Halted 2014 - Reverse Engineering the Android OS
 
My Final year project on Android app development
My Final year project on Android app developmentMy Final year project on Android app development
My Final year project on Android app development
 
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsSteelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
 
Toll app - Android project
Toll app - Android projectToll app - Android project
Toll app - Android project
 
UseCase is a DIALOG---NOT a PROCESS
UseCase is a DIALOG---NOT a PROCESSUseCase is a DIALOG---NOT a PROCESS
UseCase is a DIALOG---NOT a PROCESS
 
Activity diagram railway reservation system
Activity diagram railway reservation systemActivity diagram railway reservation system
Activity diagram railway reservation system
 
Payroll and attendance system
Payroll and attendance system Payroll and attendance system
Payroll and attendance system
 
Usecase diagram railway reservation system
Usecase diagram railway reservation systemUsecase diagram railway reservation system
Usecase diagram railway reservation system
 
Ziilion E245 final presentation
Ziilion E245 final presentationZiilion E245 final presentation
Ziilion E245 final presentation
 
Android seminar-presentation
Android seminar-presentationAndroid seminar-presentation
Android seminar-presentation
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering ppt
 

More from Stephen Gilmore

More Stochastic Simulation Examples
More Stochastic Simulation ExamplesMore Stochastic Simulation Examples
More Stochastic Simulation ExamplesStephen Gilmore
 
Testing Android apps with Robotium
Testing Android apps with RobotiumTesting Android apps with Robotium
Testing Android apps with RobotiumStephen Gilmore
 
Common Java problems when developing with Android
Common Java problems when developing with AndroidCommon Java problems when developing with Android
Common Java problems when developing with AndroidStephen Gilmore
 
Quick quiz on Objective-C
Quick quiz on Objective-CQuick quiz on Objective-C
Quick quiz on Objective-CStephen Gilmore
 
Crash Course in Objective-C
Crash Course in Objective-CCrash Course in Objective-C
Crash Course in Objective-CStephen Gilmore
 
The Stochastic Simulation Algorithm
The Stochastic Simulation AlgorithmThe Stochastic Simulation Algorithm
The Stochastic Simulation AlgorithmStephen Gilmore
 
Beginning Android Development
Beginning Android DevelopmentBeginning Android Development
Beginning Android DevelopmentStephen Gilmore
 
Computer Science Large Practical coursework
Computer Science Large Practical courseworkComputer Science Large Practical coursework
Computer Science Large Practical courseworkStephen Gilmore
 
Software Engineering Large Practical coursework
Software Engineering Large Practical courseworkSoftware Engineering Large Practical coursework
Software Engineering Large Practical courseworkStephen Gilmore
 
Introduction to the CSLP and the SELP
Introduction to the CSLP and the SELPIntroduction to the CSLP and the SELP
Introduction to the CSLP and the SELPStephen Gilmore
 
Fixing errors in Android Java applications
Fixing errors in Android Java applicationsFixing errors in Android Java applications
Fixing errors in Android Java applicationsStephen Gilmore
 
Feedback on Part 1 of the Individual Practical
Feedback on Part 1 of the Individual PracticalFeedback on Part 1 of the Individual Practical
Feedback on Part 1 of the Individual PracticalStephen Gilmore
 
Creating and working with databases in Android
Creating and working with databases in AndroidCreating and working with databases in Android
Creating and working with databases in AndroidStephen Gilmore
 
Continuing Android development
Continuing Android developmentContinuing Android development
Continuing Android developmentStephen Gilmore
 
Project management for the individual practical
Project management for the individual practicalProject management for the individual practical
Project management for the individual practicalStephen Gilmore
 
Beginning Android development
Beginning Android developmentBeginning Android development
Beginning Android developmentStephen Gilmore
 
CS/SE Individual practical - DDMS and AVD
CS/SE Individual practical - DDMS and AVDCS/SE Individual practical - DDMS and AVD
CS/SE Individual practical - DDMS and AVDStephen Gilmore
 

More from Stephen Gilmore (17)

More Stochastic Simulation Examples
More Stochastic Simulation ExamplesMore Stochastic Simulation Examples
More Stochastic Simulation Examples
 
Testing Android apps with Robotium
Testing Android apps with RobotiumTesting Android apps with Robotium
Testing Android apps with Robotium
 
Common Java problems when developing with Android
Common Java problems when developing with AndroidCommon Java problems when developing with Android
Common Java problems when developing with Android
 
Quick quiz on Objective-C
Quick quiz on Objective-CQuick quiz on Objective-C
Quick quiz on Objective-C
 
Crash Course in Objective-C
Crash Course in Objective-CCrash Course in Objective-C
Crash Course in Objective-C
 
The Stochastic Simulation Algorithm
The Stochastic Simulation AlgorithmThe Stochastic Simulation Algorithm
The Stochastic Simulation Algorithm
 
Beginning Android Development
Beginning Android DevelopmentBeginning Android Development
Beginning Android Development
 
Computer Science Large Practical coursework
Computer Science Large Practical courseworkComputer Science Large Practical coursework
Computer Science Large Practical coursework
 
Software Engineering Large Practical coursework
Software Engineering Large Practical courseworkSoftware Engineering Large Practical coursework
Software Engineering Large Practical coursework
 
Introduction to the CSLP and the SELP
Introduction to the CSLP and the SELPIntroduction to the CSLP and the SELP
Introduction to the CSLP and the SELP
 
Fixing errors in Android Java applications
Fixing errors in Android Java applicationsFixing errors in Android Java applications
Fixing errors in Android Java applications
 
Feedback on Part 1 of the Individual Practical
Feedback on Part 1 of the Individual PracticalFeedback on Part 1 of the Individual Practical
Feedback on Part 1 of the Individual Practical
 
Creating and working with databases in Android
Creating and working with databases in AndroidCreating and working with databases in Android
Creating and working with databases in Android
 
Continuing Android development
Continuing Android developmentContinuing Android development
Continuing Android development
 
Project management for the individual practical
Project management for the individual practicalProject management for the individual practical
Project management for the individual practical
 
Beginning Android development
Beginning Android developmentBeginning Android development
Beginning Android development
 
CS/SE Individual practical - DDMS and AVD
CS/SE Individual practical - DDMS and AVDCS/SE Individual practical - DDMS and AVD
CS/SE Individual practical - DDMS and AVD
 

Recently uploaded

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 

Recently uploaded (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

Arrays in Objective-C

  • 1. Computer Science Large Practical: Arrays in Objective-C Stephen Gilmore School of Informatics Friday 2nd November, 2012 Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 1 / 16
  • 2. Experience report The Desktop Team, in the University’s Information Services department have asked for feedback from you regarding your experiences (good or bad!) with Xcode in the Main Library IS Open Access Lab. This will help inform their plans for future academic years. What has been your experience? Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 2 / 16
  • 3. Programming with arrays in Objective-C Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 3 / 16
  • 4. Inspecting an array Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 4 / 16
  • 5. The XML representation Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 5 / 16
  • 6. Sorting an array Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 6 / 16
  • 7. The sorted array Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 7 / 16
  • 8. The output in the console Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 8 / 16
  • 9. Everything OK? What about “Build and Analyze”? Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 9 / 16
  • 10. Handling arrays (1/2) #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello, arrays!"); NSArray * myArray = [[NSArray alloc] initWithObjects:@"foo",@"bar",@"baz",nil]; for(NSString * myStr in myArray) { NSLog(@"-- %@", myStr); } [myArray writeToFile:@"myArray.plist" atomically:YES]; Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 10 / 16
  • 11. Handling arrays (2/2) NSArray *sortedArray = [myArray sortedArrayUsingSelector:@selector( caseInsensitiveCompare:)]; [sortedArray writeToFile:@"sortedArray.plist" atomically:YES]; for(NSString * myStr in sortedArray) { NSLog(@"---- %@", myStr); } [pool drain]; return 0; } Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 11 / 16
  • 12. Object allocation and arrays Arrays in Objective-C are not generic arrays: they can contain different kinds of objects. The nil value at the end is a terminator, signalling the end of the array. You can release an object as soon as you add it to an array because the array allocates its own memory for the object by calling retain on all objects which are added to it. arrayWithObjects auto releases from memory so you do not have to release the array yourself. If we replace [NSArray alloc] initWithObjects with arrayWithObjects then this should solve our memory leak. Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 12 / 16
  • 13. “Build and Analyze” finds no potential leaks now Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 13 / 16
  • 14. Mutable arrays NSArray objects are not mutable so we cannot update their contents. To have an array which we can update we should use NSMutableArray. Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 14 / 16
  • 15. Declaring and using mutable arrays Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 15 / 16
  • 16. Output from the program Stephen Gilmore (School of Informatics) Computer Science Large Practical Friday 2nd November, 2012 16 / 16