如何访问 Swift 1.2 ACAccount 对象的 _properties Dictionary 对象?
How does one access the _properties Dictionary object of a Swift 1.2 ACAccount object?
在 XCode 中添加断点向我展示了一个 Swift 1.2 ACAccount 对象有一个 _properties 对象,它又持有 key/value对@user_id:0123456789。我需要访问这个数值。我已阅读文档、Google 搜索、SO 搜索并盲目尝试以下所有方法均无济于事:
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" ) - 拼写 "properties" 和“_properties” - 产生 Builtin.RawPointer 的结果.不知道有没有用
采用更强类型的方法可能更容易,以下方法适用于我的新 iOS 项目:
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)
}
}
}
在 XCode 中添加断点向我展示了一个 Swift 1.2 ACAccount 对象有一个 _properties 对象,它又持有 key/value对@user_id:0123456789。我需要访问这个数值。我已阅读文档、Google 搜索、SO 搜索并盲目尝试以下所有方法均无济于事:
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" ) - 拼写 "properties" 和“_properties” - 产生 Builtin.RawPointer 的结果.不知道有没有用
采用更强类型的方法可能更容易,以下方法适用于我的新 iOS 项目:
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)
}
}
}