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
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
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

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Dernier (20)

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

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
  • 6.
  • 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
  • 19.
  • 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...