Git Product home page Git Product logo

gulliver's Introduction

Gulliver

A Swift wrapper for the iOS AddressBook framework.

What's in the box?

Enums

  • AuthorizationStatus: ABAuthorizationStatus
  • CompositeNameFormat: ABPersonCompositeNameFormat
  • ImageFormat: ABPersonImageFormat
  • PersonKind: "ABPersonKind" (CFNumberRef)
  • PropertyKind: ABPropertyType
  • SortOrdering: ABPersonSortOrdering
  • SourceKind: ABSourceType
  • RecordKind: ABRecordType

The enums that come with AddressBook.framework are gross. They aren't declared correctly. Instead of using CF_ENUM and CF_OPTIONS, AddressBook.framework prefers to create anonymous enums followed by a typedef-ed type.

What this means is that you have ABRecordType aliased to UInt32 and three orphan declarations (kABPersonType, kABGroupType, kABSourceType) imported to Swift as Ints.

As well, the kABPersonKindProperty property does not contain an ABPersonKind wrapped in a CFNumberRef. It contains either kABPersonKindPerson or kABPersonKindOrganization (both static CFNumberRefs).

Helpers

Pay no attention to the man behind the curtain.

Implementation details live here, such as:

  • An extension for Zachary Waldowski's brilliant Lustre framework that allows easier creation of ResultType values with CFErrorRef errors.
  • Block-based external change registration (and dereigstration) for ABAddressBookRefs. The ABAddressBookRegisterExternalChangeCallback function requires a function pointer to call when an external change happens. Swift imports this required type as useless CFunctionPointer; for this reason, a non-lethal amount of Objective-C is used here.

Multi Value Types

  • AlternateBirthday
  • Date
  • Email
  • InstantMessage
  • PhoneNumber
  • PostalAddress
  • RelatedName
  • SocialProfile
  • URL

These "multi value types" are structs that represent the values in an ABMultiValueRef. As you may have guessed, Date is a wrapper around NSDate, and Email, RelatedName, and URL are wrappers around String. These exist for easy conversion between appropriate CFTypeRef values for addition to multi value objects and also for improved type safety.

Protocols

  • AddressBookType
  • GroupType
  • MultiValueRepresentable
  • PersonType
  • RecordType
  • SourceType

AddressBookType enumerates the responsibilities and requirements of an address book object, and similar for GroupType, PersonType, and SourceType.

These protocols exist so you can use them in your app instead of concrete types. Why? The AddressBook framework is a black box and not easily testable. Now, you can use the *Type protocols to supply valid dummy data in your tests.

Instead of using an ABAddressBookRef internally, you can pass in an AddressBookType-conforming value into your class (via dependency injection).

Before:

struct PersonViewModel {
    private let addressBook: ABAddressBookRef

    init() {
        // Create addressBook here
    }
}

After:

struct PersonViewModel<AB: AddressBookType> {
    private let addressBook: AB

    init(addressBook: AB) {
        // Assign addressBook here
    }
}

Types

  • AddressBook, Group, Person, Record, Source: Concrete implementations of the respective *Type protocols that are backed by ABAddressBook and ABRecordRef values.
  • MultiValue: A parameterized value that represents a type-safe view on a ABMultiValueRef's labeled contents.
  • {,Readable,Writable}PropertyType, Property, MutableProperty: Lenses on the values contained in RecordType values.

Availability

Lustre is intended for Swift 1.2. Compatibility with future versions is not guaranteed.

Gulliver?

The name "Gulliver" comes from the title of Travels into Several Remote Nations of the World. In Four Parts. By Lemuel Gulliver, First a Surgeon, and then a Captain of Several Ships (commonly known as Gulliver's Travels), a satirical novel by Jonathan Swift (a Swift famous long before Taylor).

gulliver's People

Contributors

a2 avatar neonichu avatar

Watchers

James Cloos avatar  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.