2017-08-07 21:41:37.458 [**App name redacted**][5316:2314238] ***
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSCFData isEqualToString:]: unrecognized selector sent to instance 0x6080000b97b0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000119ce4d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000011a7c121e objc_exception_throw + 48
2 CoreFoundation 0x0000000119d54f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
// Sanity check that we are capable of migrating the data.
NSMutableSet *const keysToMigrate = [NSMutableSet new];
for (NSDictionary *const keychainEntry in queryResultWithData) {
NSString *const key = keychainEntry[(__bridge id)kSecAttrAccount];
if ([key isEqualToString:VALCanAccessKeychainCanaryKey]) /** ERROR OCCURS HERE **/ {
// We don't care about this key. Move along.
/*
Adding an entry to the keychain when a matching entry already exists will throw an error.
To properly add an entry to the keychain:
1. Check for any matching keychain entries.
2. If a matching entry exists, update.
3. If no matching entries are found, insert a new entry.
*/
...
// Sanity check that we are capable of migrating the data.
NSMutableSet *const keysToMigrate = [NSMutableSet new];
for (NSDictionary *const keychainEntry in queryResultWithData) {
NSString *const key = keychainEntry[(__bridge id)kSecAttrAccount];
if ([key isEqualToString:VALCanAccessKeychainCanaryKey]) /** ERROR OCCURS HERE **/ {
// We don't care about this key. Move along.
continue;
/** Create a Data object **/
let dataBlob = "foo".data(using: .utf8)
let existingEntryData: [String: Any] = [
kSecAttrService as String!: Bundle.main.bundleIdentifier as Any,
// Use Data object for kSecAttrAccount, which expects a String
kSecAttrAccount as String!: dataBlob as Any,
kSecClass as String!: kSecClassGenericPassword as Any,
kSecValueData as String!: dataBlob as Any
- (void)test_migrateObjectsMatchingQueryRemoveOnCompletion_withNSDataAsAccount_doesNotRaiseException;
{
NSString *identifier = @"my_identifier";
NSData *dataBlob = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
// kSecAttrAccount entry is expected to be a CFString, but a CFDataRef can also be stored as a value.
NSDictionary *keychainData = @{
(__bridge id)kSecAttrService : identifier,
(__bridge id)kSecClass : (__bridge id)kSecClassGenericPassword,
OSStatus
SecItemUpdate(CFDictionaryRef query, CFDictionaryRef attributesToUpdate)
{
...
OSStatus status_osx = errSecItemNotFound, status_ios = errSecItemNotFound;
bool can_target_ios, can_target_osx;
OSStatus status = SecItemCategorizeQuery(query, can_target_ios, can_target_osx);
...
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, to
class DrawerViewController: UIViewController { | |
var button = UIButton() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
button.addTarget(self, action: #selector(onButtonTap), for: .touchUpInside) | |
// ... | |
} | |
@objc private func onButtonTap() { |
class MyViewController: UIViewController { | |
let button = UIButton() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
button.addTarget(self, action: #selector(onButtonTap), for: .touchUpInside) | |
// ... | |
} | |
@objc private func onButtonTap() { |