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

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 

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