1

Adding a breakpoint in XCode has shown me that a Swift 1.2 ACAccount object has a _properties object, which in turn holds the key/value pair of @user_id: 0123456789. I need to access this numerical value. I have read the docs, Googled, SO'ed and blindly tried all of the following to no avail:

let accountStore = ACAccountStore()
let accountType = accountStore.accountTypeWithAccountTypeIdentifier( ACAccountTypeIdentifierTwitter )
let allACAccounts = accountStore.accountsWithAccountType( accountType )
let someACAccount = allACAccounts[ 0 ]

someACAccount.valueForKey( "properties" )
someACAccount.mutableArrayValueForKey( "properties" )
someACAccount.valueForKeyPath( "properties" )
someACAccount.valueForUndefinedKey("properties")
someACAccount.valueForKey( "user_id" )
someACAccount.mutableArrayValueForKey( "user_id" )
someACAccount.valueForKeyPath( "user_id" )
someACAccount.valueForUndefinedKey("user_id")
someACAccount.properties
someACAccount._properties
someACAccount.user_id

someACAccount.valueForKey( "properties" ) - both spelled "properties" and "_properties" - produces the result of a Builtin.RawPointer. I do not know if that is useful or not.

nhgrif
  • 61,578
  • 25
  • 134
  • 173
Joseph Beuys' Mum
  • 2,395
  • 2
  • 24
  • 50

1 Answers1

3

It might be easier to take a more strongly-typed approach, the following works for me on a fresh iOS project:

    let store = ACAccountStore()
    let type = store.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)

    store.requestAccessToAccountsWithType(type, options: nil) { success, error in

        if success, let accounts = store.accountsWithAccountType(type),
            account = accounts.first as? ACAccount
        {
            println(account.username)

            if let properties = account.valueForKey("properties") as? [String:String],
                   user_id = properties["user_id"] {
                    println(user_id)
            }
        }

    }
Airspeed Velocity
  • 40,491
  • 8
  • 113
  • 118
  • Interesting @airspeed-velocity, that seems to work. I think the *Book of Ecclesiastes* will need updating for the twenty-first century to also read "...there is a time to weakly type, and a time to strongly type." – Joseph Beuys' Mum Apr 12 '15 at 16:31