Giter Site home page Giter Site logo

richdonne / swiftaddressbook Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ningsuhen/swiftaddressbook

0.0 2.0 0.0 160 KB

Complete wrapper for the ABAddressBook C-Framework for iOS, written in Swift to be typesafe and convenient

License: Apache License 2.0

Ruby 2.21% Swift 97.63% C++ 0.16%

swiftaddressbook's Introduction

SwiftAddressBook - A strong-typed Swift Wrapper for ABAddressBook

CI Status Version License Platform

Complete wrapper for the ABAddressBook C-Framework for iOS, written in Swift to be typesafe and convenient

Note: please use https://github.com/SocialbitGmbH/SwiftAddressBook/tree/Swift_1.2_take2 while the Swift 1.2 compatible version is not merged to the main branch.

Description

It is tedious and requires very much reading in the documentation if you want to understand the ABAddressBook in iOS. To provide a solution, this wrapper uses Swift, which is strong-typed (unlike c). It also circumvents the use of unsafe c-pointers when accessing ABAddressBook from Swift, by directly casting them to the correct type. All properties, previously only available via the correct key, can now be accessed conveniently via variables.

Here´s how you would access ABAddressBook via SwiftAddressBook: How To

Some minimal examples below:

  1. Request access
swiftAddressBook?.requestAccessWithCompletion({ (success, error) -> Void in
    if success {
      //do something with swiftAddressBook
    }
    else {
      //no success. Optionally evaluate error
    }
})
  1. Use Addressbook: - Get array of all people and log their phone numbers)
    if let people = swiftAddressBook?.allPeople {
        for person in people {
          NSLog("%@", person.phoneNumbers?.map( {$0.value} ))
        }
    }
- Create Contacts
  ```Swift
  var person = SwiftAddressBookPerson.create()
  person.firstName = "John"
  
  var email = MultivalueEntry(value: "[email protected]", label: "home", id: 0)
  person.emails = [email]
  
  swiftAddressBook?.addRecord(person)
  swiftAddressBook?.save()
  ```

Complicated Swift typecasting to NS-..., thousand times of unwrapping optionals, figuring out which constant is the key to your person property, distinguishing between group, source or person - nothing that you have to deal with any more

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

SwiftAddressBook is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SwiftAddressBook"

Note: version 0.36 requires you to also specify the flag

use_frameworks!

as documented here and then import SwiftAddressBook in your project (and import AddressBook for using constants from ABAddressBook)

If you don´t want to use CocoaPods, or need to maintain iOS7 compatibility, just copy all files from the folder Pod/Classes into your project. This way, you don´t need to import SwiftAddressBook-

License

Copyright 2014 Socialbit GmbH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.   

swiftaddressbook's People

Contributors

takeanice avatar albertbori avatar edekhayser avatar

Watchers

James Cloos avatar Ant Donn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.