SlideShare a Scribd company logo
1 of 21
Download to read offline
My Favourite Ten Xcode Things


Tuesday, October 11, 11

Some of my favourite Xcode and Objective-C type things.
(Or: Please tell me a better way of
                                  doing these things)


Tuesday, October 11, 11

Three phases of iPhone development:

1. Argh! Square brackets!
2. Ok, how do I do this?
3. Ok, what’s the BEST way to do this?

The common theme is that each stage is full of puzzles, and puzzles are attractive to certain
types of brains. You think, you solve, you get a little rush. Addictive!
1. Xcode Keyboard Shortcuts

                          Flip between .h and .m

                             Control + Command + Arrow up

                          Switch between open tabs

                             Shift + Command + [ or ]

                          Find anywhere in project

                             Shift + Command + F

Tuesday, October 11, 11

I spend many hours using Xcode every day. The transition to Xcode 4 wasn’t too bad,
although it took a while to get used to the way it splits views. I’m happy enough now though.
At least it’s not Eclipse, and when I go back to Visual Studio it irritates me that I need to
double-click on things a lot.
1b. Xcode Keyboard Shortcuts



                          Toggle Debug Console

                             Shift + Command + Y

                          Open a file

                             Shift + Command + O



Tuesday, October 11, 11

Open a file is fantastic. Use it.
2. Drag from the NIB editor into .h files




                          Hold down Control and drag a control into
                          your .h file, to create actions and properties
                          (and the associated methods in .m).




Tuesday, October 11, 11

I love this.
3. Useful NSString initialization



                          -(NSString *)getAxis
                {
                ! return [NSString stringWithFormat:
                       @"X:%0.2f Y:%0.2f Z:%0.2f",
                       _accelerometer[0],
                       _accelerometer[1],
                       _accelerometer[2]];
                }




Tuesday, October 11, 11

Very nice - and because there is no ALLOC, it’s an autorelease object.
Just don’t put a BOOL in there.
3b. Useful NSString initialization




                          BOOL myStatus = TRUE;

                  -(NSString *)getStatus
                  {
                !   return [NSString stringWithFormat:
                       @"%@",(myStatus ? @”YES” : @”NO”)];
                  }




Tuesday, October 11, 11

Handy for NSLog too.
4. Useful NSString comparisons

                          Don’t check to see if a string is empty like
                          this:
                          if (myString == nil)   { NSLog(@"empty!"); }



                          Use this:

                          if ([myString isEqualToString:@""]) { NSLog(@"empty!"); }


                          Or this:
                          if ([myString length] == 0) { NSLog(@"empty!"); }




Tuesday, October 11, 11

But if it’s just whitespace, that might not work..
4b. Useful NSString comparisons



                          //	
  Mr.	
  Will	
  Shipley
                static	
  inline	
  BOOL	
  isEmpty(id	
  thing)	
  {
                	
  	
  	
  	
  return	
  thing	
  ==	
  nil
                	
  	
  	
  	
  ||	
  [thing	
  isKindOfClass:[NSNull	
  class]]
                	
  	
  	
  	
  ||	
  ([thing	
  respondsToSelector:@selector(length)]
                	
  	
  	
  	
  	
  	
  	
  	
  &&	
  [(NSData	
  *)thing	
  length]	
  ==	
  0)
                	
  	
  	
  	
  ||	
  ([thing	
  respondsToSelector:@selector(count)]
                	
  	
  	
  	
  	
  	
  	
  	
  &&	
  [(NSArray	
  *)thing	
  count]	
  ==	
  0);
                }




Tuesday, October 11, 11

Here’s the 100% best way.
5. Testing to see if a file exists



                          There is no file system. Except there is.



                    if ([[NSFileManager defaultManager]
                         fileExistsAtPath:[[NSBundle mainBundle]
                         pathForResource:@"picture" ofType:@"jpg"]])

                             return YES;




Tuesday, October 11, 11

Also, are you using large image files? Tempted to stick with PNG? Try JPG instead.
Same quality in photograph images, but can be 1/10th of the size.
6. Time delay before method call

                          -(void) myMethod
                {

                }

                [self performSelector:@selector(myMethod)
                        withObject: nil
                        afterDelay: 1.0];




                [NSObject
                cancelPreviousPerformRequestsWithTarget              :self
                        selector :@selector(myMethod)
                        object :nil];


Tuesday, October 11, 11

Multithreading for dummies - a great way to get animation working when the main thread
would otherwise be blocked. WARNING! Remember to cancel it if you don’t use it before the
reference goes away!
7. Delegate callback to parent AppDelegate

                   // In AppDelegate
                -(void)callMe
                {


                }



                // In some other class
                - (void)viewDidLoad
                {
                    [super viewDidLoad];

                          [(AppDelegate*)
                           [[UIApplication sharedApplication] delegate] callMe];

                }




Tuesday, October 11, 11

Just need to add callMe to .h in AppDelegate, and #import that into the other class.
However, think about why you are doing this: it’s very likely that a Singleton will be a better
idea.
8. Using delegates to perform actions when
                modal dialog closed.
                          // In the Modal Dialog UIViewController Class, .h
                          file

                @interface CityPickerViewController : UIViewController
                <UIPickerViewDelegate>

                {
                !
                ! id delegate;
                !
                }

                - (id)delegate;
                - (void)setDelegate:(id)newDelegate;

                @end




Tuesday, October 11, 11

So you want to trigger something when a modal dialog is closed. Use this to allow the Modal
dialog UIViewController class to call a method back in the class that called it.
8b. Using delegates to perform actions
                when modal dialog closed.
                          // In the Modal Dialog UIViewController Class, .m file

                - (id)delegate {
                    return delegate;
                }

                - (void)setDelegate:(id)newDelegate {
                    delegate = newDelegate;
                }

                -(void) updateCity: (id)sender
                {
                ! // replaced by delegated call
                !
                }

                -(void)callWhenDialogClosing
                {
                ! [[self delegate] updateCity:self];!
                }




Tuesday, October 11, 11

So you want to trigger something when a modal dialog is closed. Use this to allow the Modal
dialog UIViewController class to call a method back in the class that called it.
8b. Using delegates to perform actions
                when modal dialog closed.
                          // In the class that is calling the modal dialog

                -(void) updateCity: (id)sender
                {
                ! [self drawLocation];!
                  [myPickerView dismissModalViewControllerAnimated:YES];
                }


                -(IBAction) clickNearestCity: (id)sender
                {
                     myPickerView = [[CityPickerViewController alloc]
                initWithNibName:@"CityPickerViewController" bundle:nil];


                ! myPickerView.delegate = self;
                     ....




Tuesday, October 11, 11

You can’t keep the pointer to the view nice and local now, as you’ll need to close it yourself in
the delegate. Yes, it smells a bit. Suggestions welcome.
9. Two-part animation block



                [UIView beginAnimations:@"clickBounce" context:tempButton];

                [UIView setAnimationDelegate:self];

                [UIView setAnimationDuration:0.2]; !

                [UIView setAnimationDidStopSelector:@selector(part2:finished:context:)];

                [myButton setTransform:CGAffineTransformMakeScale(.9,.9)];

                [UIView commitAnimations];




Tuesday, October 11, 11

Blocks have a terribly ugly syntax, but if you can get over it, they are useful. And increasing
in importance. If you wanted an animation to have multiple parts, you needed to use the
DidStopSelector, and it was a pain.
9b. Two-part animation block


                [UIView animateWithDuration:1.0

                          animations:^
                          {
                               myButton.alpha = 1.0;
                               myButton.transform = CGAffineTransformMakeScale(1.5, 1.5);
                          }

                          completion:^(BOOL completed)
                          {
                               myButton.alpha = 0.8;
                               myButton.transform = CGAffineTransformMakeScale(1, 1);
                          }
                ];




Tuesday, October 11, 11

Much neater, no extra methods, easier to pass values between different components of the
animation etc etc
10. UICollections, Tags and iOS 5



                    Declare a Collection, and then link all your
                    buttons to it..
                          IBOutletCollection(UIButton) NSArray *menuButtonsCollection;




Tuesday, October 11, 11

Piece of cake in NIB editor.
10b. UICollections, Tags and iOS 5


                    Now you can iterate over them all..
              for (UIButton *button in menuButtonsCollection)
               {
                     [button setImage:[UIImage imageNamed:@"pic.png"]
                             forState:UIControlStateNormal];
               }




Tuesday, October 11, 11

Handy to programmatically fade out all buttons for example.
Remember you can also set TAGS in the NIB editor, and then act on those in the loop.
You don’t need to only use one type of object, use (id) for any control.
10b. UICollections, Tags and iOS 5



                  If you need to change them all at once..
                  [[UISwitch appearance] setOnTintColor: [UIColor redColor]];




Tuesday, October 11, 11

Note: need to re-open the view to see the changes.
johntkennedy@gmail.com


Tuesday, October 11, 11

More Related Content

What's hot

Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascriptDoeun KOCH
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScriptTodd Anglin
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackNelson Glauber Leal
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinKai Koenig
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confFabio Collini
 
Reactive Programming with JavaScript
Reactive Programming with JavaScriptReactive Programming with JavaScript
Reactive Programming with JavaScriptCodemotion
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJWORKS powered by Ordina
 
Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard LibraryNelson Glauber Leal
 
Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design PrinciplesJon Kruger
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesDragos Ionita
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot CampTroy Miles
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackAplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackNelson Glauber Leal
 
Automatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightAutomatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightGiuseppe Arici
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScripttaobao.com
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmFabio Collini
 
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Ray Ploski
 

What's hot (20)

Let's JavaScript
Let's JavaScriptLet's JavaScript
Let's JavaScript
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
Objective-C for Beginners
Objective-C for BeginnersObjective-C for Beginners
Objective-C for Beginners
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & Jetpack
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with Kotlin
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community conf
 
Reactive Programming with JavaScript
Reactive Programming with JavaScriptReactive Programming with JavaScript
Reactive Programming with JavaScript
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard Library
 
Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design Principles
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackAplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e Jetpack
 
Automatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightAutomatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma Night
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere Stockholm
 
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
 

Similar to My Favourite 10 Things about Xcode/ObjectiveC

Five class-based views everyone has written by now
Five class-based views everyone has written by nowFive class-based views everyone has written by now
Five class-based views everyone has written by nowJames Aylett
 
Grand Central Dispatch Design Patterns
Grand Central Dispatch Design PatternsGrand Central Dispatch Design Patterns
Grand Central Dispatch Design PatternsRobert Brown
 
Learning iOS and hunting NSZombies in 3 weeks
Learning iOS and hunting NSZombies in 3 weeksLearning iOS and hunting NSZombies in 3 weeks
Learning iOS and hunting NSZombies in 3 weeksCalvin Cheng
 
Scalable JavaScript Design Patterns
Scalable JavaScript Design PatternsScalable JavaScript Design Patterns
Scalable JavaScript Design PatternsAddy Osmani
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101ygv2000
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery PluginRavi Mone
 
Ios development
Ios developmentIos development
Ios developmentelnaqah
 
So, you think you know widgets.
So, you think you know widgets.So, you think you know widgets.
So, you think you know widgets.danielericlee
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 14 of 185
The Ring programming language version 1.5.4 book - Part 14 of 185The Ring programming language version 1.5.4 book - Part 14 of 185
The Ring programming language version 1.5.4 book - Part 14 of 185Mahmoud Samir Fayed
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlinAdit Lal
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android developmentAdit Lal
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)Piyush Katariya
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends旻琦 潘
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and ContainersRodolfo Carvalho
 
iOS Selectors Blocks and Delegation
iOS Selectors Blocks and DelegationiOS Selectors Blocks and Delegation
iOS Selectors Blocks and DelegationJussi Pohjolainen
 

Similar to My Favourite 10 Things about Xcode/ObjectiveC (20)

Five class-based views everyone has written by now
Five class-based views everyone has written by nowFive class-based views everyone has written by now
Five class-based views everyone has written by now
 
Grand Central Dispatch Design Patterns
Grand Central Dispatch Design PatternsGrand Central Dispatch Design Patterns
Grand Central Dispatch Design Patterns
 
Learning iOS and hunting NSZombies in 3 weeks
Learning iOS and hunting NSZombies in 3 weeksLearning iOS and hunting NSZombies in 3 weeks
Learning iOS and hunting NSZombies in 3 weeks
 
Scalable JavaScript Design Patterns
Scalable JavaScript Design PatternsScalable JavaScript Design Patterns
Scalable JavaScript Design Patterns
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
 
Ios development
Ios developmentIos development
Ios development
 
Thinking In Swift
Thinking In SwiftThinking In Swift
Thinking In Swift
 
So, you think you know widgets.
So, you think you know widgets.So, you think you know widgets.
So, you think you know widgets.
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84
 
03 objective-c session 3
03  objective-c session 303  objective-c session 3
03 objective-c session 3
 
The Ring programming language version 1.5.4 book - Part 14 of 185
The Ring programming language version 1.5.4 book - Part 14 of 185The Ring programming language version 1.5.4 book - Part 14 of 185
The Ring programming language version 1.5.4 book - Part 14 of 185
 
Rubymotion talk
Rubymotion talkRubymotion talk
Rubymotion talk
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlin
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android development
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
iOS Selectors Blocks and Delegation
iOS Selectors Blocks and DelegationiOS Selectors Blocks and Delegation
iOS Selectors Blocks and Delegation
 
Testable Javascript
Testable JavascriptTestable Javascript
Testable Javascript
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

My Favourite 10 Things about Xcode/ObjectiveC

  • 1. My Favourite Ten Xcode Things Tuesday, October 11, 11 Some of my favourite Xcode and Objective-C type things.
  • 2. (Or: Please tell me a better way of doing these things) Tuesday, October 11, 11 Three phases of iPhone development: 1. Argh! Square brackets! 2. Ok, how do I do this? 3. Ok, what’s the BEST way to do this? The common theme is that each stage is full of puzzles, and puzzles are attractive to certain types of brains. You think, you solve, you get a little rush. Addictive!
  • 3. 1. Xcode Keyboard Shortcuts Flip between .h and .m Control + Command + Arrow up Switch between open tabs Shift + Command + [ or ] Find anywhere in project Shift + Command + F Tuesday, October 11, 11 I spend many hours using Xcode every day. The transition to Xcode 4 wasn’t too bad, although it took a while to get used to the way it splits views. I’m happy enough now though. At least it’s not Eclipse, and when I go back to Visual Studio it irritates me that I need to double-click on things a lot.
  • 4. 1b. Xcode Keyboard Shortcuts Toggle Debug Console Shift + Command + Y Open a file Shift + Command + O Tuesday, October 11, 11 Open a file is fantastic. Use it.
  • 5. 2. Drag from the NIB editor into .h files Hold down Control and drag a control into your .h file, to create actions and properties (and the associated methods in .m). Tuesday, October 11, 11 I love this.
  • 6. 3. Useful NSString initialization -(NSString *)getAxis { ! return [NSString stringWithFormat: @"X:%0.2f Y:%0.2f Z:%0.2f", _accelerometer[0], _accelerometer[1], _accelerometer[2]]; } Tuesday, October 11, 11 Very nice - and because there is no ALLOC, it’s an autorelease object. Just don’t put a BOOL in there.
  • 7. 3b. Useful NSString initialization BOOL myStatus = TRUE; -(NSString *)getStatus { ! return [NSString stringWithFormat: @"%@",(myStatus ? @”YES” : @”NO”)]; } Tuesday, October 11, 11 Handy for NSLog too.
  • 8. 4. Useful NSString comparisons Don’t check to see if a string is empty like this: if (myString == nil) { NSLog(@"empty!"); } Use this: if ([myString isEqualToString:@""]) { NSLog(@"empty!"); } Or this: if ([myString length] == 0) { NSLog(@"empty!"); } Tuesday, October 11, 11 But if it’s just whitespace, that might not work..
  • 9. 4b. Useful NSString comparisons //  Mr.  Will  Shipley static  inline  BOOL  isEmpty(id  thing)  {        return  thing  ==  nil        ||  [thing  isKindOfClass:[NSNull  class]]        ||  ([thing  respondsToSelector:@selector(length)]                &&  [(NSData  *)thing  length]  ==  0)        ||  ([thing  respondsToSelector:@selector(count)]                &&  [(NSArray  *)thing  count]  ==  0); } Tuesday, October 11, 11 Here’s the 100% best way.
  • 10. 5. Testing to see if a file exists There is no file system. Except there is. if ([[NSFileManager defaultManager] fileExistsAtPath:[[NSBundle mainBundle] pathForResource:@"picture" ofType:@"jpg"]]) return YES; Tuesday, October 11, 11 Also, are you using large image files? Tempted to stick with PNG? Try JPG instead. Same quality in photograph images, but can be 1/10th of the size.
  • 11. 6. Time delay before method call -(void) myMethod { } [self performSelector:@selector(myMethod) withObject: nil afterDelay: 1.0]; [NSObject cancelPreviousPerformRequestsWithTarget :self selector :@selector(myMethod) object :nil]; Tuesday, October 11, 11 Multithreading for dummies - a great way to get animation working when the main thread would otherwise be blocked. WARNING! Remember to cancel it if you don’t use it before the reference goes away!
  • 12. 7. Delegate callback to parent AppDelegate // In AppDelegate -(void)callMe { } // In some other class - (void)viewDidLoad { [super viewDidLoad]; [(AppDelegate*) [[UIApplication sharedApplication] delegate] callMe]; } Tuesday, October 11, 11 Just need to add callMe to .h in AppDelegate, and #import that into the other class. However, think about why you are doing this: it’s very likely that a Singleton will be a better idea.
  • 13. 8. Using delegates to perform actions when modal dialog closed. // In the Modal Dialog UIViewController Class, .h file @interface CityPickerViewController : UIViewController <UIPickerViewDelegate> { ! ! id delegate; ! } - (id)delegate; - (void)setDelegate:(id)newDelegate; @end Tuesday, October 11, 11 So you want to trigger something when a modal dialog is closed. Use this to allow the Modal dialog UIViewController class to call a method back in the class that called it.
  • 14. 8b. Using delegates to perform actions when modal dialog closed. // In the Modal Dialog UIViewController Class, .m file - (id)delegate { return delegate; } - (void)setDelegate:(id)newDelegate { delegate = newDelegate; } -(void) updateCity: (id)sender { ! // replaced by delegated call ! } -(void)callWhenDialogClosing { ! [[self delegate] updateCity:self];! } Tuesday, October 11, 11 So you want to trigger something when a modal dialog is closed. Use this to allow the Modal dialog UIViewController class to call a method back in the class that called it.
  • 15. 8b. Using delegates to perform actions when modal dialog closed. // In the class that is calling the modal dialog -(void) updateCity: (id)sender { ! [self drawLocation];! [myPickerView dismissModalViewControllerAnimated:YES]; } -(IBAction) clickNearestCity: (id)sender { myPickerView = [[CityPickerViewController alloc] initWithNibName:@"CityPickerViewController" bundle:nil]; ! myPickerView.delegate = self; .... Tuesday, October 11, 11 You can’t keep the pointer to the view nice and local now, as you’ll need to close it yourself in the delegate. Yes, it smells a bit. Suggestions welcome.
  • 16. 9. Two-part animation block [UIView beginAnimations:@"clickBounce" context:tempButton]; [UIView setAnimationDelegate:self]; [UIView setAnimationDuration:0.2]; ! [UIView setAnimationDidStopSelector:@selector(part2:finished:context:)]; [myButton setTransform:CGAffineTransformMakeScale(.9,.9)]; [UIView commitAnimations]; Tuesday, October 11, 11 Blocks have a terribly ugly syntax, but if you can get over it, they are useful. And increasing in importance. If you wanted an animation to have multiple parts, you needed to use the DidStopSelector, and it was a pain.
  • 17. 9b. Two-part animation block [UIView animateWithDuration:1.0 animations:^ { myButton.alpha = 1.0; myButton.transform = CGAffineTransformMakeScale(1.5, 1.5); } completion:^(BOOL completed) { myButton.alpha = 0.8; myButton.transform = CGAffineTransformMakeScale(1, 1); } ]; Tuesday, October 11, 11 Much neater, no extra methods, easier to pass values between different components of the animation etc etc
  • 18. 10. UICollections, Tags and iOS 5 Declare a Collection, and then link all your buttons to it.. IBOutletCollection(UIButton) NSArray *menuButtonsCollection; Tuesday, October 11, 11 Piece of cake in NIB editor.
  • 19. 10b. UICollections, Tags and iOS 5 Now you can iterate over them all.. for (UIButton *button in menuButtonsCollection) { [button setImage:[UIImage imageNamed:@"pic.png"] forState:UIControlStateNormal]; } Tuesday, October 11, 11 Handy to programmatically fade out all buttons for example. Remember you can also set TAGS in the NIB editor, and then act on those in the loop. You don’t need to only use one type of object, use (id) for any control.
  • 20. 10b. UICollections, Tags and iOS 5 If you need to change them all at once.. [[UISwitch appearance] setOnTintColor: [UIColor redColor]]; Tuesday, October 11, 11 Note: need to re-open the view to see the changes.