SlideShare une entreprise Scribd logo
1  sur  32
Application Settings
 and User Defaults
  - Parimal Satyal (realityequation.net)
                     October 28, 2009




     Based on Chapter 10 ‘Application Settings and User Defaults’
   Apress Beginning iPhone 3 Development: Exploring the iPhone SDK
                     by Dave Mark and Jeff LaMarch
Prefs

Most Mac apps have ‘Preferences’
Persistent Data/Settings
Settings app on iPhone OS
UI is built for you, uses plist
Settings
Apps can have own
tab in the Settings app
When in-app, when in
Settings app?
‘Backdoor’ prefs that
don’t need changing
Else, users must quit
UPrefs: Utility App
Utility App Goodness
Free UI
Free ‘flip side
view’ (animated)
Custom UIView
subclasses:
 MainView
 FlipsideView
iPhone Dev: Application Settings and Defaults
Settings Bundle

‘Settings Bundle’ to provide the data
Each bundle must have Root.plist
Additional views through
additional plists as child views
in Root.plist
New File > Resource
Root.plist Format
Root node is always a dictionary
(so must have key and value)
Children nodes can be:
 Dictionaries • capable of containing other data
 Arrays • capable of containing other data
 Boolean
 Data
 Number
 String

StringsTable for localization; ignore
PreferenceSpecifiers
PreferenceSpecifiers
PreferenceSpecifiers




-      Required: Type, Key, (Title)
PreferenceSpecifiers

               Key




                     Key




-      Required: Type, Key, (Title)
-       Key vs Key: Confusing
Adding Stuff
      and Grouping
Notice change in icons when expanded


PSGroupSpecifier signals new group
The contents of Root.plist determine
the UI and structure of Settings app
Other Inputs
Secure Text Field (isSecure key)
Multivalue field: PSMultiValueSpecifier
 Array as child, with separate
 Key list and Value list
Toggle Switch: PSToggleSwitchSpecifier
Slider: PSSliderSpecifier
Editing Root.plist
Editing Root.plist
Array to Drill Down
iPhone Dev: Application Settings and Defaults
Magic of Root.plist

Open Root.plist
Spend some time playing around and
seeing what changes what
Add another control:
A Toggle, a Slider or just a Text Field
Getting Settings data
 Easy, using the NSUserDefaults class
 NSUserDefaults *defaults =
 [NSUserDefaults standardUserDefaults];

 defaultsbecomes a dictionary, so we can
 do stuff like:
 (NSString *) objectForKey:
 (NSDate *) objectForKey:
 (int) intForKey:
 (BOOL) boolForKey:
UI: MainView.xib
MainViewController
Explore the .h and .m files
Take a look at these methods:
 refreshFields:
 flipSideViewControllerDidFinish:
 viewDidAppear:

Declaring constants, creating a method
Property-ize and synthesize elements
Map them using NSUserDefaults class &
objectForKey: method
MainViewController.m
   - (void) refreshFields {
	 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	 usernameLabel.text = [defaults objectForKey: kUsernameKey];
	 passwordLabel.text = [defaults objectForKey: kPasswordKey];
	 languageLabel.text = [defaults objectForKey: kLanguageKey];
	 beAwesomeLabel.text = [defaults objectForKey: kBeAwesomeKey];
	 awesomenessLabel.text = [[defaults objectForKey: kAwesomenessKey]
stringValue];
}

- (void) viewDidAppear:(BOOL)animated {
	 [self refreshFields];
	 [super viewDidAppear:animated];
}
MainViewController.m
   - (void) refreshFields {
	 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	 usernameLabel.text = [defaults objectForKey: kUsernameKey];
	 passwordLabel.text = [defaults objectForKey: kPasswordKey];
	 languageLabel.text = [defaults objectForKey: kLanguageKey];
	 beAwesomeLabel.text = [defaults objectForKey: kBeAwesomeKey];
	 awesomenessLabel.text = [[defaults objectForKey: kAwesomenessKey]
stringValue]; ‹ don’t forget stringValue
}

- (void) viewDidAppear:(BOOL)animated {
	 [self refreshFields];
	 [super viewDidAppear:animated];
}
Changing Defaults

Design UI
Create outlets
Use getters and setters to make the
changes
FlipsideView.xib
Get what’s there when view loads
FlipsideViewController.m
    - (void)viewDidLoad {

    [super viewDidLoad];

	 NSUserDefaults *defaults = [NSUserDefaults
standardUserDefaults];

	 awesomeSwitch.on = ([[defaults objectForKey:kBeAwesomeKey]
isEqualToString:@"Oui"]) ? YES: NO;

	 awesomenessSlider.value = [defaults
floatForKey:kAwesomenessKey];

}
Set new values when moving out
FlipsideViewController.m
  - (void) viewWillDisappear:(BOOL)animated {

	 NSUserDefaults *defaults = [NSUserDefaults
standardUserDefaults];

	 NSString *prefValue = (awesomeSwitch.on)? @"Oui" :
@"Non";

	 [defaults setObject:prefValue forKey:kBeAwesomeKey];
	 [defaults setFloat:awesomenessSlider.value
forKey:kAwesomenessKey];

	 [super viewWillDisappear:animated];
}
Finishing Up

Clean up with dealloc, viewDidUnload for
both Views
Fix any Build errors
And you get...
iPhone Dev: Application Settings and Defaults
iPhone Dev: Application Settings and Defaults

Contenu connexe

Tendances

New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3markstory
 
Changes to Drupal Themes in version 7 (part 1)
Changes to Drupal Themes in version 7 (part 1)Changes to Drupal Themes in version 7 (part 1)
Changes to Drupal Themes in version 7 (part 1)Chris Charlton
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entitiesdrubb
 
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway ichikaway
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntityBasuke Suzuki
 
Development Approach
Development ApproachDevelopment Approach
Development Approachalexkingorg
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPressWalter Ebert
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntityBasuke Suzuki
 
Modular javascript
Modular javascriptModular javascript
Modular javascriptZain Shaikh
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHPmarkstory
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaionglslarmenta
 
PostgreSQL (2) by Aswin
PostgreSQL (2) by AswinPostgreSQL (2) by Aswin
PostgreSQL (2) by AswinAgate Studio
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Php Data Objects
Php Data ObjectsPhp Data Objects
Php Data Objectshiren.joshi
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-entechbed
 

Tendances (19)

New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
 
Changes to Drupal Themes in version 7 (part 1)
Changes to Drupal Themes in version 7 (part 1)Changes to Drupal Themes in version 7 (part 1)
Changes to Drupal Themes in version 7 (part 1)
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
 
Quiz With Answers Drupal
Quiz With  Answers  DrupalQuiz With  Answers  Drupal
Quiz With Answers Drupal
 
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
 
Drupal 8 Hooks
Drupal 8 HooksDrupal 8 Hooks
Drupal 8 Hooks
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
Development Approach
Development ApproachDevelopment Approach
Development Approach
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPress
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
Modular javascript
Modular javascriptModular javascript
Modular javascript
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
Field api.From d7 to d8
Field api.From d7 to d8Field api.From d7 to d8
Field api.From d7 to d8
 
CakeFest 2013 keynote
CakeFest 2013 keynoteCakeFest 2013 keynote
CakeFest 2013 keynote
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
 
PostgreSQL (2) by Aswin
PostgreSQL (2) by AswinPostgreSQL (2) by Aswin
PostgreSQL (2) by Aswin
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Php Data Objects
Php Data ObjectsPhp Data Objects
Php Data Objects
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
 

Similaire à iPhone Dev: Application Settings and Defaults

Drupal 7 Entity & Entity API
Drupal 7 Entity & Entity APIDrupal 7 Entity & Entity API
Drupal 7 Entity & Entity API均民 戴
 
Drupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comDrupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comJD Leonard
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS DrupalMumbai
 
iOS Course day 2
iOS Course day 2iOS Course day 2
iOS Course day 2Rich Allen
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentNuvole
 
Sencha Touch - Introduction
Sencha Touch - IntroductionSencha Touch - Introduction
Sencha Touch - IntroductionABC-GROEP.BE
 
Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto UniversitySC5.io
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolGordon Forsythe
 
Modular programming Using Object in Scala
Modular programming Using Object in ScalaModular programming Using Object in Scala
Modular programming Using Object in ScalaKnoldus Inc.
 
Entities in drupal 7
Entities in drupal 7Entities in drupal 7
Entities in drupal 7Zsolt Tasnadi
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008maximgrp
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...smn-automate
 

Similaire à iPhone Dev: Application Settings and Defaults (20)

Django
DjangoDjango
Django
 
Drupal 7 Entity & Entity API
Drupal 7 Entity & Entity APIDrupal 7 Entity & Entity API
Drupal 7 Entity & Entity API
 
KAAccessControl
KAAccessControlKAAccessControl
KAAccessControl
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
Les22
Les22Les22
Les22
 
Drupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comDrupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.com
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
 
iOS Course day 2
iOS Course day 2iOS Course day 2
iOS Course day 2
 
Play 2.0
Play 2.0Play 2.0
Play 2.0
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 
Sencha Touch - Introduction
Sencha Touch - IntroductionSencha Touch - Introduction
Sencha Touch - Introduction
 
Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto University
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Modular programming Using Object in Scala
Modular programming Using Object in ScalaModular programming Using Object in Scala
Modular programming Using Object in Scala
 
Entities in drupal 7
Entities in drupal 7Entities in drupal 7
Entities in drupal 7
 
Session 2- day 3
Session 2- day 3Session 2- day 3
Session 2- day 3
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
 

Dernier

VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 

Dernier (20)

VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 

iPhone Dev: Application Settings and Defaults

  • 1. Application Settings and User Defaults - Parimal Satyal (realityequation.net) October 28, 2009 Based on Chapter 10 ‘Application Settings and User Defaults’ Apress Beginning iPhone 3 Development: Exploring the iPhone SDK by Dave Mark and Jeff LaMarch
  • 2. Prefs Most Mac apps have ‘Preferences’ Persistent Data/Settings Settings app on iPhone OS UI is built for you, uses plist
  • 3. Settings Apps can have own tab in the Settings app When in-app, when in Settings app? ‘Backdoor’ prefs that don’t need changing Else, users must quit
  • 5. Utility App Goodness Free UI Free ‘flip side view’ (animated) Custom UIView subclasses: MainView FlipsideView
  • 7. Settings Bundle ‘Settings Bundle’ to provide the data Each bundle must have Root.plist Additional views through additional plists as child views in Root.plist
  • 8. New File > Resource
  • 9. Root.plist Format Root node is always a dictionary (so must have key and value) Children nodes can be: Dictionaries • capable of containing other data Arrays • capable of containing other data Boolean Data Number String StringsTable for localization; ignore
  • 12. PreferenceSpecifiers - Required: Type, Key, (Title)
  • 13. PreferenceSpecifiers Key Key - Required: Type, Key, (Title) - Key vs Key: Confusing
  • 14. Adding Stuff and Grouping Notice change in icons when expanded PSGroupSpecifier signals new group The contents of Root.plist determine the UI and structure of Settings app
  • 15. Other Inputs Secure Text Field (isSecure key) Multivalue field: PSMultiValueSpecifier Array as child, with separate Key list and Value list Toggle Switch: PSToggleSwitchSpecifier Slider: PSSliderSpecifier
  • 20. Magic of Root.plist Open Root.plist Spend some time playing around and seeing what changes what Add another control: A Toggle, a Slider or just a Text Field
  • 21. Getting Settings data Easy, using the NSUserDefaults class NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; defaultsbecomes a dictionary, so we can do stuff like: (NSString *) objectForKey: (NSDate *) objectForKey: (int) intForKey: (BOOL) boolForKey:
  • 23. MainViewController Explore the .h and .m files Take a look at these methods: refreshFields: flipSideViewControllerDidFinish: viewDidAppear: Declaring constants, creating a method Property-ize and synthesize elements Map them using NSUserDefaults class & objectForKey: method
  • 24. MainViewController.m - (void) refreshFields { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; usernameLabel.text = [defaults objectForKey: kUsernameKey]; passwordLabel.text = [defaults objectForKey: kPasswordKey]; languageLabel.text = [defaults objectForKey: kLanguageKey]; beAwesomeLabel.text = [defaults objectForKey: kBeAwesomeKey]; awesomenessLabel.text = [[defaults objectForKey: kAwesomenessKey] stringValue]; } - (void) viewDidAppear:(BOOL)animated { [self refreshFields]; [super viewDidAppear:animated]; }
  • 25. MainViewController.m - (void) refreshFields { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; usernameLabel.text = [defaults objectForKey: kUsernameKey]; passwordLabel.text = [defaults objectForKey: kPasswordKey]; languageLabel.text = [defaults objectForKey: kLanguageKey]; beAwesomeLabel.text = [defaults objectForKey: kBeAwesomeKey]; awesomenessLabel.text = [[defaults objectForKey: kAwesomenessKey] stringValue]; ‹ don’t forget stringValue } - (void) viewDidAppear:(BOOL)animated { [self refreshFields]; [super viewDidAppear:animated]; }
  • 26. Changing Defaults Design UI Create outlets Use getters and setters to make the changes
  • 28. Get what’s there when view loads FlipsideViewController.m - (void)viewDidLoad { [super viewDidLoad]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; awesomeSwitch.on = ([[defaults objectForKey:kBeAwesomeKey] isEqualToString:@"Oui"]) ? YES: NO; awesomenessSlider.value = [defaults floatForKey:kAwesomenessKey]; }
  • 29. Set new values when moving out FlipsideViewController.m - (void) viewWillDisappear:(BOOL)animated { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *prefValue = (awesomeSwitch.on)? @"Oui" : @"Non"; [defaults setObject:prefValue forKey:kBeAwesomeKey]; [defaults setFloat:awesomenessSlider.value forKey:kAwesomenessKey]; [super viewWillDisappear:animated]; }
  • 30. Finishing Up Clean up with dealloc, viewDidUnload for both Views Fix any Build errors And you get...