SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
AddressBook.swi, 
Alexsander*Akers*,*@a2
Address&Book&“Classes” 
ABAddressBookRef 
An#address#book. 
ABRecordRef 
A"person,"group,"or"source. 
ABMultiValueRef 
A"mul&'valued"property.
Why$AB_____Ref? 
When%AddressBook.framework%debuted%in%Mac%OS%X% 
10.2%Jaguar,%it%featured%both%CBbased%Core% 
FoundaDon%and%ObjecDveBC%APIs.%However,%when% 
the%iPhone%SDK%became%public%with%the%release%of% 
iPhone%OS%2.0,%its%AddressBook.framework%only% 
featured%the%CBbased%Core%FoundaDon%API. 
tl;dr 
C"based(Core(Founda.on(APIs(aren't(difficult(to(use,( 
per(se,(but(Swi<(makes(it(a(bit(harder.
ABAddressBookRef 
An#address#book.
ABAddressBookRef+Crea.on 
Objec&ve(C 
extern ABAddressBookRef ABAddressBookCreateWithOptions( 
CFDictionaryRef options, 
CFErrorRef *error 
); 
Swi$ 
func ABAddressBookCreateWithOptions( 
options: CFDictionaryRef!, 
error: UnsafeMutablePointer<Unmanaged<CFErrorRef>?> 
) -> Unmanaged<ABAddressBook>!
ABAddressBookRef+Crea.on 
var error: Unmanaged<CFErrorRef>? = nil 
var addressBook: ABAddressBookRef? = 
ABAddressBookCreateWithOptions(nil, &error)?.takeRetainedValue() 
if let addressBook = addressBook { 
// Success! 
} else { 
// Error 
let e = error!.takeUnretainedValue() as AnyObject as NSError 
println("An error occurred: (e)") 
}
ABAddressBookRef+Authoriza2on 
let addressBook: ABAddressBookRef = /* ... */ 
ABAddressBookRequestAccessWithCompletion(addressBook) { 
(success, error) in 
if success { 
// We can use the address book. 
} else { 
// User denied the request. 
let e = error as AnyObject as NSError 
println("An error occurred: (e)") 
} 
}
ABRecordRef 
A"person,"group,"or"source.
ABRecordRef 
Person
ABRecordRef 
Group
ABRecordRef 
Source
ABRecordRef*Acquisi/on 
let peoplePickerDelegate = /* some object */ 
let peoplePicker = ABPeoplePickerNavigationController() 
peoplePicker.delegate = peoplePickerDelegate 
viewController.presentViewController( 
peoplePicker, 
animated: true, 
completion: nil 
)
ABRecordRef*Acquisi/on 
// In your ABPeoplePickerNavigationControllerDelegate 
func peoplePickerNavigationController( 
peoplePicker: ABPeoplePickerNavigationController!, 
didSelectPerson person: ABRecord!) { 
// Do something with person 
} 
func peoplePickerNavigationControllerDidCancel( 
peoplePicker: ABPeoplePickerNavigationController!) { 
let p = peoplePicker.presentingViewController! 
p.dismissViewControllerAnimated(true, completion: nil) 
}
ABRecordRef*Acquisi/on 
let addressBook: ABAddressBookRef = /* ... */ 
// You can get a record's ID with ABRecordGetID() 
let recordID: ABRecordID = /* ... */ 
let unmanagedPerson: Unmanaged<ABRecordRef>? = 
ABAddressBookGetPersonWithRecordID(addressBook, recordID) 
// ABAddressBookGetGroupWithRecordID 
// ABAddressBookGetSourceWithRecordID 
if let person = unmanagedPerson?.takeUnretainedValue() { 
// You have a person! 
}
ABRecordRef*Values 
func ABRecordCopyValue( 
record: ABRecord!, 
property: ABPropertyID 
) -> Unmanaged<AnyObject>! 
let kABPersonFirstNameProperty: ABPropertyID 
let kABPersonMiddleNameProperty: ABPropertyID 
let kABPersonLastNameProperty: ABPropertyID 
// etc.
ABRecordRef*Values 
let firstName: CFStringRef = ABRecordCopyValue( 
record, 
kABPersonFirstNameProperty 
)?.takeRetainedValue() 
if firstName != nil { 
let fn = firstName! as AnyObject as String 
println("The first name is (fn).") 
}
ABRecordRef*Values 
let phones: ABMultiValueRef? = ABRecordCopyValue( 
record, 
kABPersonPhoneProperty 
)?.takeRetainedValue() 
if let phones = phones { 
// We have an ABMultiValueRef. 
}
ABMul&ValueRef 
A"mul&'valued"property.
ABMul&ValueRef 
Almost'a'dic,onary?'! 
// Duplicate keys are bad. 
let phones: [String : String] = [ 
"Home": "+1 (718) 861-4986", 
"Work": "+1 (212) 340-1938", 
"iPhone": "+1 (917) 530-9127", 
"iPhone": "+1 (917) 251-8826" 
] 
Keys%in%a%mul,-value%don't%have%to%be%unique.%A% 
person%could%have%two%mobile%numbers,%like%the%day% 
iPhone%/%night%iPhone%guy.
ABMul&ValueRef 
An#array#of#tuples.#! 
let phones: [(String, String)] = [ 
("Home", "+1 (718) 861-4986"), 
("Work", "+1 (212) 340-1938"), 
("iPhone", "+1 (917) 530-9127"), 
("iPhone", "+1 (917) 251-8826") 
] 
This%representa,on%makes%more%sense%because%the% 
uniqueness%contstraint%is%gone.%The%tuple%consists%of%a% 
label%and%a%value.
ABMul&ValueRef 
let count: Int = ABMultiValueGetCount(phones) 
for i in 0..<count { 
let label: String = ABMultiValueCopyLabelAtIndex( 
phones, i 
)!.takeRetainedValue() as AnyObject as String 
let value: String = ABMultiValueCopyValueAtIndex( 
phones, i 
)!.takeRetainedValue() as AnyObject as String 
println("(label) -> (value)") 
}
ABMul&ValueRef 
Debugger'Output 
_$!<Home>!$_ -> +1 (718) 861-4986 
_$!<Work>!$_ -> +1 (212) 340-1938 
iPhone -> +1 (917) 530-9127 
iPhone -> +1 (917) 251-8826
_$!<WTF>!$_ 
_$!<Home>!$_ !!→!!!kABHomeLabel 
_$!<Work>!$_ !!→!!!kABWorkLabel 
_$!<Other>!$_!!→!!!kABOtherLabel 
These%are%just%some%of%the%constants%used%by% 
AddressBook.framework%that%are%localized%in%Phone,% 
Contacts%and%ABPersonViewController%before% 
display%to%the%user.
AddressBook.swi, 
Alexsander*Akers*,*@a2

Contenu connexe

Tendances

Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.jsJay Phelps
 
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014Amazon Web Services
 
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaPutting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaGalen Charlton
 
【AWS Developers Meetup】RESTful APIをChaliceで紐解く
【AWS Developers Meetup】RESTful APIをChaliceで紐解く【AWS Developers Meetup】RESTful APIをChaliceで紐解く
【AWS Developers Meetup】RESTful APIをChaliceで紐解くAmazon Web Services Japan
 
Awash in a sea of connections
Awash in a sea of connectionsAwash in a sea of connections
Awash in a sea of connectionsGalen Charlton
 
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014Amazon Web Services
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Workhorse Computing
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to doPuppet
 
Evolving Software with Moose
Evolving Software with MooseEvolving Software with Moose
Evolving Software with MooseDave Cross
 
Scala Workshop
Scala WorkshopScala Workshop
Scala WorkshopClueda AG
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceAmazon Web Services
 
Symfony Under the Hood
Symfony Under the HoodSymfony Under the Hood
Symfony Under the HoodeZ Systems
 
Переход на Scala: босиком по граблям
Переход на Scala: босиком по граблямПереход на Scala: босиком по граблям
Переход на Scala: босиком по граблямSveta Bozhko
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceAmazon Web Services
 
Intro To Moose
Intro To MooseIntro To Moose
Intro To MoosecPanel
 
Rails 3.1 Asset Pipeline
Rails 3.1 Asset PipelineRails 3.1 Asset Pipeline
Rails 3.1 Asset Pipelineeallam
 
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...Puppet
 

Tendances (20)

Fewd week6 slides
Fewd week6 slidesFewd week6 slides
Fewd week6 slides
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.js
 
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
 
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaPutting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
 
【AWS Developers Meetup】RESTful APIをChaliceで紐解く
【AWS Developers Meetup】RESTful APIをChaliceで紐解く【AWS Developers Meetup】RESTful APIをChaliceで紐解く
【AWS Developers Meetup】RESTful APIをChaliceで紐解く
 
Awash in a sea of connections
Awash in a sea of connectionsAwash in a sea of connections
Awash in a sea of connections
 
Moose
MooseMoose
Moose
 
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to do
 
Evolving Software with Moose
Evolving Software with MooseEvolving Software with Moose
Evolving Software with Moose
 
Drupal, meet Assetic
Drupal, meet AsseticDrupal, meet Assetic
Drupal, meet Assetic
 
Scala Workshop
Scala WorkshopScala Workshop
Scala Workshop
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
 
Symfony Under the Hood
Symfony Under the HoodSymfony Under the Hood
Symfony Under the Hood
 
Переход на Scala: босиком по граблям
Переход на Scala: босиком по граблямПереход на Scala: босиком по граблям
Переход на Scala: босиком по граблям
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
 
Intro To Moose
Intro To MooseIntro To Moose
Intro To Moose
 
Rails 3.1 Asset Pipeline
Rails 3.1 Asset PipelineRails 3.1 Asset Pipeline
Rails 3.1 Asset Pipeline
 
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...
 

Similaire à ABAddressBookRef and ABRecordRef for accessing contacts

Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love RubyBen Scheirman
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-CEddie Kao
 
A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalQA or the Highway
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record.toster
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of RubyTom Crinson
 
Refactor like a boss
Refactor like a bossRefactor like a boss
Refactor like a bossgsterndale
 
Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)Andre Foeken
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worldsChristopher Spring
 

Similaire à ABAddressBookRef and ABRecordRef for accessing contacts (20)

Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-C
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 
A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert Fornal
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of Ruby
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
Ruby gems
Ruby gemsRuby gems
Ruby gems
 
Refactor like a boss
Refactor like a bossRefactor like a boss
Refactor like a boss
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Ruby 2.0
Ruby 2.0Ruby 2.0
Ruby 2.0
 
Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worlds
 
Class
ClassClass
Class
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
PHP code examples
PHP code examplesPHP code examples
PHP code examples
 
Ruby
RubyRuby
Ruby
 

Dernier

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Dernier (20)

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 

ABAddressBookRef and ABRecordRef for accessing contacts

  • 2. Address&Book&“Classes” ABAddressBookRef An#address#book. ABRecordRef A"person,"group,"or"source. ABMultiValueRef A"mul&'valued"property.
  • 3. Why$AB_____Ref? When%AddressBook.framework%debuted%in%Mac%OS%X% 10.2%Jaguar,%it%featured%both%CBbased%Core% FoundaDon%and%ObjecDveBC%APIs.%However,%when% the%iPhone%SDK%became%public%with%the%release%of% iPhone%OS%2.0,%its%AddressBook.framework%only% featured%the%CBbased%Core%FoundaDon%API. tl;dr C"based(Core(Founda.on(APIs(aren't(difficult(to(use,( per(se,(but(Swi<(makes(it(a(bit(harder.
  • 5. ABAddressBookRef+Crea.on Objec&ve(C extern ABAddressBookRef ABAddressBookCreateWithOptions( CFDictionaryRef options, CFErrorRef *error ); Swi$ func ABAddressBookCreateWithOptions( options: CFDictionaryRef!, error: UnsafeMutablePointer<Unmanaged<CFErrorRef>?> ) -> Unmanaged<ABAddressBook>!
  • 6. ABAddressBookRef+Crea.on var error: Unmanaged<CFErrorRef>? = nil var addressBook: ABAddressBookRef? = ABAddressBookCreateWithOptions(nil, &error)?.takeRetainedValue() if let addressBook = addressBook { // Success! } else { // Error let e = error!.takeUnretainedValue() as AnyObject as NSError println("An error occurred: (e)") }
  • 7. ABAddressBookRef+Authoriza2on let addressBook: ABAddressBookRef = /* ... */ ABAddressBookRequestAccessWithCompletion(addressBook) { (success, error) in if success { // We can use the address book. } else { // User denied the request. let e = error as AnyObject as NSError println("An error occurred: (e)") } }
  • 12. ABRecordRef*Acquisi/on let peoplePickerDelegate = /* some object */ let peoplePicker = ABPeoplePickerNavigationController() peoplePicker.delegate = peoplePickerDelegate viewController.presentViewController( peoplePicker, animated: true, completion: nil )
  • 13. ABRecordRef*Acquisi/on // In your ABPeoplePickerNavigationControllerDelegate func peoplePickerNavigationController( peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!) { // Do something with person } func peoplePickerNavigationControllerDidCancel( peoplePicker: ABPeoplePickerNavigationController!) { let p = peoplePicker.presentingViewController! p.dismissViewControllerAnimated(true, completion: nil) }
  • 14. ABRecordRef*Acquisi/on let addressBook: ABAddressBookRef = /* ... */ // You can get a record's ID with ABRecordGetID() let recordID: ABRecordID = /* ... */ let unmanagedPerson: Unmanaged<ABRecordRef>? = ABAddressBookGetPersonWithRecordID(addressBook, recordID) // ABAddressBookGetGroupWithRecordID // ABAddressBookGetSourceWithRecordID if let person = unmanagedPerson?.takeUnretainedValue() { // You have a person! }
  • 15. ABRecordRef*Values func ABRecordCopyValue( record: ABRecord!, property: ABPropertyID ) -> Unmanaged<AnyObject>! let kABPersonFirstNameProperty: ABPropertyID let kABPersonMiddleNameProperty: ABPropertyID let kABPersonLastNameProperty: ABPropertyID // etc.
  • 16. ABRecordRef*Values let firstName: CFStringRef = ABRecordCopyValue( record, kABPersonFirstNameProperty )?.takeRetainedValue() if firstName != nil { let fn = firstName! as AnyObject as String println("The first name is (fn).") }
  • 17. ABRecordRef*Values let phones: ABMultiValueRef? = ABRecordCopyValue( record, kABPersonPhoneProperty )?.takeRetainedValue() if let phones = phones { // We have an ABMultiValueRef. }
  • 19. ABMul&ValueRef Almost'a'dic,onary?'! // Duplicate keys are bad. let phones: [String : String] = [ "Home": "+1 (718) 861-4986", "Work": "+1 (212) 340-1938", "iPhone": "+1 (917) 530-9127", "iPhone": "+1 (917) 251-8826" ] Keys%in%a%mul,-value%don't%have%to%be%unique.%A% person%could%have%two%mobile%numbers,%like%the%day% iPhone%/%night%iPhone%guy.
  • 20. ABMul&ValueRef An#array#of#tuples.#! let phones: [(String, String)] = [ ("Home", "+1 (718) 861-4986"), ("Work", "+1 (212) 340-1938"), ("iPhone", "+1 (917) 530-9127"), ("iPhone", "+1 (917) 251-8826") ] This%representa,on%makes%more%sense%because%the% uniqueness%contstraint%is%gone.%The%tuple%consists%of%a% label%and%a%value.
  • 21. ABMul&ValueRef let count: Int = ABMultiValueGetCount(phones) for i in 0..<count { let label: String = ABMultiValueCopyLabelAtIndex( phones, i )!.takeRetainedValue() as AnyObject as String let value: String = ABMultiValueCopyValueAtIndex( phones, i )!.takeRetainedValue() as AnyObject as String println("(label) -> (value)") }
  • 22. ABMul&ValueRef Debugger'Output _$!<Home>!$_ -> +1 (718) 861-4986 _$!<Work>!$_ -> +1 (212) 340-1938 iPhone -> +1 (917) 530-9127 iPhone -> +1 (917) 251-8826
  • 23. _$!<WTF>!$_ _$!<Home>!$_ !!→!!!kABHomeLabel _$!<Work>!$_ !!→!!!kABWorkLabel _$!<Other>!$_!!→!!!kABOtherLabel These%are%just%some%of%the%constants%used%by% AddressBook.framework%that%are%localized%in%Phone,% Contacts%and%ABPersonViewController%before% display%to%the%user.