gpt4 book ai didi

swift - 如何访问 Swift 1.2 ACAccount 对象的 _properties Dictionary 对象?

转载 作者:搜寻专家 更新时间:2023-11-01 06:46:59 24 4
gpt4 key购买 nike

在 XCode 中添加断点向我展示了 Swift 1.2 ACAccount 对象有一个 _properties 对象,该对象又包含 @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)
}
}

}

关于swift - 如何访问 Swift 1.2 ACAccount 对象的 _properties Dictionary 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29589483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com