returning a nsdictionary from a method? [closed] - ios
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
#import <Foundation/Foundation.h>
#interface GenerarPassword: NSObject
{
int password;
}
#property int password;
-(NSString*) GenerarValor:(NSString*) key;
-(NSDictionary*) getDiccionario;
-(int) password;
//-(NSArray*)generarlistaletras:(int)numero;
-(int) generarClave;
-(void) printPassword;
-(void)setPassword:(int)nuevoValor;
/*
-(int) generarNumeroAleatorio;
-(NSArray *) generarListadeUsuarios;
*/
#end
#import <Foundation/Foundation.h>
#include <stdlib.h>
#include "GenerarPassword.h"
#implementation GenerarPassword
-(NSDictionary*) getDiccionario
{
NSDictionary* m_Dict =[NSDictionary dictionaryWithObjectsAndKeys:
#"1", #"Dx",
#"2", #"Om",
#"3", #"Al",
#"4", #"Dx",
#"5", #"Je",
#"6", #"Ko",
#"7", #"Ke",
#"8", #"Fi",
#"9", #"Re",
#"10", #"Me",
#"11", #"Mu",
#"12", #"Ra",
#"13", #"Lu",
#"14", #"Lo",
#"15", #"Ka"];
return m_Dict;
}
-(int) password
{
return password;
}
-(void) setPassword:(int)nuevoValor
{
password = nuevoValor;
}
-(void) printPassword
{
NSLog(#"%d",password);
}
/*Se genera la clave numérica*/
-(int) generarClave
{
srand(time(0));
int r = rand() %(9999-1000+1) +1000;
return r;
}
//- (NSArray*) generarlistaletras:(int)numero
//{
// return nil;
//}
//Esta función Genera el valor Aleatorio
-(NSString*) GenerarValor:(NSString*) key
{
NSString *valor = [[self generarDiccionario] valueForKey: key];
return valor;
}
// return (generarDiccionario().get(key))
// lista = [0,0,0]
//lista[random.randrange(0,3)] = [GenerarValor(numero)]
//for i in range(len(lista)):
// if lista[i] == 0:
// lista[i] = [GenerarValor(random.randrange(11,20))]
// return lista
#end
int main(int argc, char const *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
GenerarPassword *Generar1 = [[GenerarPassword alloc]init];
int clave = [Generar1 generarClave];
[Generar1 setPassword: clave];
NSDictionary* dict = [Generar1 getDiccionario];
NSLog(#"%a",[Generar1 GenerarValor: #"3"]);
[pool drain];
return 0;
}
I am really desperate, i just want to use the dictionary but at the compiling time i get a few warnings and when i run the program i get the following error: ": Uncaught exception NSInvalidArgumentException, reason: Can not determine type information for -[GenerarPassword (null)]
"
I see missing nil at the end of the object/key list:
NSDictionary* m_Dict =[NSDictionary dictionaryWithObjectsAndKeys:
#"1", #"Dx",
#"2", #"Om",
#"3", #"Al",
#"4", #"Dx",
#"5", #"Je",
#"6", #"Ko",
#"7", #"Ke",
#"8", #"Fi",
#"9", #"Re",
#"10", #"Me",
#"11", #"Mu",
#"12", #"Ra",
#"13", #"Lu",
#"14", #"Lo",
#"15", #"Ka",
nil];
return m_Dict;
}
and generarDiccionario method not declared (I don't see any method matching this name). Did you mean getDiccionario?
-(NSString*) GenerarValor:(NSString*) key
{
NSString *valor = [[self getDiccionario] valueForKey: key];
return valor;
}
On my environment, NSInvalidArgumentException didn't appeared. But there are some mistakes to fix.
On the method 'dictionaryWithObjectsAndKeys', you must first write the object , then the key, nil for last.
NSDictionary *m_Dict = [NSDictionary dictionaryWithObjectsAndKeys:
#"Dx", #"1",
#"Om", #"2",
#"Al", #"3",
#"Dx", #"4",
#"Je", #"5",
#"Ko", #"6",
#"Ke", #"7",
#"Fi", #"8",
#"Re", #"9",
#"Me", #"10",
#"Mu", #"11",
#"Ra", #"12",
#"Lu", #"13",
#"Lo", #"14",
#"Ka", #"15",
nil];
There is no method 'generarDiccionario'. Do you mean 'getDiccionario'?
- (NSString *)GenerarValor:(NSString *)key
{
//NSString *valor = [[self generarDiccionario] valueForKey: key]; <-Not found
NSString *valor = [[self getDiccionario] valueForKey: key]; //Do you mean this?
return valor;
}
The format identifier is '%#' for NSString*.
NSLog(#"%a",[Generar1 GenerarValor: #"3"]); //Error
NSLog(#"%#",[Generar1 GenerarValor: #"3"]);
Perhaps it will work after fix them.
Related
NSMutableArray count is 0 after initWithObject
I've defined a property of NSMutableArray. Right after calling initWithObjects, it's count is 0. What am I missing here? Here's my code: #interface MainViewController () #property NSMutableArray *photos; #end - (void)viewDidLoad { [super viewDidLoad]; _photos = [_photos initWithObjects:#"1", #"2", #"3", nil]; NSLog(#"Photos count: %lu",(unsigned long)_photos.count); //prints 0 }
This is because _photos is nil at the time that you are trying to call the init method. Use arrayWithObjects instead: _photos = [NSMutableArray arrayWithObjects:#"1", #"2", #"3", nil];
It is illegal to say init... without saying alloc in the same line. alloc is a class method, and your class is NSMutableArray, so you should have said: _photos = [[NSMutableArray alloc] initWithObjects:#"1", #"2", #"3", nil];
I have to create a mutable dictionary but i am getting an "Incompatible pointer types initializing" error
I am trying to create a dictionary that will contain a key with a value 'Object_Info'. I have the following code and get this error: Incompatible pointer types initializing 'NSMutableDictionary *' with an expression of type 'NSDictionary *' Here is my code: #import <Foundation/Foundation.h> #interface Object_Info : NSObject { NSString *product; float cost; int qty; } #end #implementation Object_Info -(id) init { if (self = [super init]){ product = #""; cost = 0.0; qty = 0; } return self; } #end int main(int argc, const char * argv[]) { #autoreleasepool { NSMutableDictionary *stock = #{ //ERROR IS HERE!!!!! #"Lawn Chair" : [Object_Info new], #"Beach Chair" : [Object_Info new], #"Kitchen Chair" : [Object_Info new], #"Futon" : [Object_Info new], }; for(NSString *key in [stock allKeys]) { NSLog(#"%#",[stock objectForKey:key]); } } return 0; }
The problem you're having is that you are trying to assign an NSDictionary to a NSMutableDictionary. Try this: NSMutableDictionary *stock = [NSMutableDictionary new]; [stock setDictionary:#{ #"Lawn Chair" : [Object_Info new], #"Beach Chair" : [Object_Info new], #"Kitchen Chair" : [Object_Info new], #"Futon" : [Object_Info new], }];
Native iOS Country Picker
I'm developing an app with an custom Registration Flow, where the user should set his nationality or his home Country. My question is, if it's possible to get this information via an native ViewController like ABPeoplePickerNavigationController for contacts. Should look like this (iPhone 6, iOS 8.x, contacts App 'select a Country'): Thanks
It is very easy to make your own Country Picker. You can get the country list(country codes) easily from NSLocale, NSArray *countryArray = [NSLocale ISOCountryCodes]; Also you will get the country name list using displayNameForKey method, NSLocale *locale = [NSLocale currentLocale]; NSMutableArray *sortedCountryArray = [[NSMutableArray alloc] init]; for (NSString *countryCode in countryArray) { NSString *displayNameString = [locale displayNameForKey:NSLocaleCountryCode value:countryCode]; [sortedCountryArray addObject:displayNameString]; } [sortedCountryArray sortUsingSelector:#selector(localizedCompare:)]; Just use the sortedCountryArray for populating tableView in your picker class.
I think you have to make your own one using modal view controller. Alternatively, you can use this one, which works quite well.
No there isn't a built-in picker for countries. Same about the classic picture reader, its the stuff you have to make yourself. Thankfully, it's rather easy to make and find, wether you want someone else's (lockwood is a very realiable programmer, i'm sure his CountryPicker is great). Or you can go the harder way and make one yourself from scratch. Note that if you have all the country codes (BE, FR, EN, NL, PT, etc.) you can find the localized name with iOS. What I did in my code was importing a massive static dictionary of all country codes, and simply use their localized names in the tableview. This is how I got all the codes (and international prefixes, because my app needs that). - (NSMutableDictionary*)dialCodeDict{ NSMutableDictionary *dialCodeDict = [[NSMutableDictionary alloc]initWithObjectsAndKeys: #"972", #"IL", #"93", #"AF", #"355", #"AL", #"213", #"DZ", #"1", #"AS", #"376", #"AD", #"244", #"AO", #"1", #"AI", #"1", #"AG", #"54", #"AR", #"374", #"AM", #"297", #"AW", #"61", #"AU", #"43", #"AT", #"994", #"AZ", #"1", #"BS", #"973", #"BH", #"880", #"BD", #"1", #"BB", #"375", #"BY", #"32", #"BE", #"501", #"BZ", #"229", #"BJ", #"1", #"BM", #"975", #"BT", #"387", #"BA", #"267", #"BW", #"55", #"BR", #"246", #"IO", #"359", #"BG", #"226", #"BF", #"257", #"BI", #"855", #"KH", #"237", #"CM", #"1", #"CA", #"238", #"CV", #"345", #"KY", #"236", #"CF", #"235", #"TD", #"56", #"CL", #"86", #"CN", #"61", #"CX", #"57", #"CO", #"269", #"KM", #"242", #"CG", #"682", #"CK", #"506", #"CR", #"385", #"HR", #"53", #"CU", #"537", #"CY", #"420", #"CZ", #"45", #"DK", #"253", #"DJ", #"1", #"DM", #"1", #"DO", #"593", #"EC", #"20", #"EG", #"503", #"SV", #"240", #"GQ", #"291", #"ER", #"372", #"EE", #"251", #"ET", #"298", #"FO", #"679", #"FJ", #"358", #"FI", #"33", #"FR", #"594", #"GF", #"689", #"PF", #"241", #"GA", #"220", #"GM", #"995", #"GE", #"49", #"DE", #"233", #"GH", #"350", #"GI", #"30", #"GR", #"299", #"GL", #"1", #"GD", #"590", #"GP", #"1", #"GU", #"502", #"GT", #"224", #"GN", #"245", #"GW", #"595", #"GY", #"509", #"HT", #"504", #"HN", #"36", #"HU", #"354", #"IS", #"91", #"IN", #"62", #"ID", #"964", #"IQ", #"353", #"IE", #"972", #"IL", #"39", #"IT", #"1", #"JM", #"81", #"JP", #"962", #"JO", #"77", #"KZ", #"254", #"KE", #"686", #"KI", #"965", #"KW", #"996", #"KG", #"371", #"LV", #"961", #"LB", #"266", #"LS", #"231", #"LR", #"423", #"LI", #"370", #"LT", #"352", #"LU", #"261", #"MG", #"265", #"MW", #"60", #"MY", #"960", #"MV", #"223", #"ML", #"356", #"MT", #"692", #"MH", #"596", #"MQ", #"222", #"MR", #"230", #"MU", #"262", #"YT", #"52", #"MX", #"377", #"MC", #"976", #"MN", #"382", #"ME", #"1", #"MS", #"212", #"MA", #"95", #"MM", #"264", #"NA", #"674", #"NR", #"977", #"NP", #"31", #"NL", #"599", #"AN", #"687", #"NC", #"64", #"NZ", #"505", #"NI", #"227", #"NE", #"234", #"NG", #"683", #"NU", #"672", #"NF", #"1", #"MP", #"47", #"NO", #"968", #"OM", #"92", #"PK", #"680", #"PW", #"507", #"PA", #"675", #"PG", #"595", #"PY", #"51", #"PE", #"63", #"PH", #"48", #"PL", #"351", #"PT", #"1", #"PR", #"974", #"QA", #"40", #"RO", #"250", #"RW", #"685", #"WS", #"378", #"SM", #"966", #"SA", #"221", #"SN", #"381", #"RS", #"248", #"SC", #"232", #"SL", #"65", #"SG", #"421", #"SK", #"386", #"SI", #"677", #"SB", #"27", #"ZA", #"500", #"GS", #"34", #"ES", #"94", #"LK", #"249", #"SD", #"597", #"SR", #"268", #"SZ", #"46", #"SE", #"41", #"CH", #"992", #"TJ", #"66", #"TH", #"228", #"TG", #"690", #"TK", #"676", #"TO", #"1", #"TT", #"216", #"TN", #"90", #"TR", #"993", #"TM", #"1", #"TC", #"688", #"TV", #"256", #"UG", #"380", #"UA", #"971", #"AE", #"44", #"GB", #"1", #"US", #"598", #"UY", #"998", #"UZ", #"678", #"VU", #"681", #"WF", #"967", #"YE", #"260", #"ZM", #"263", #"ZW", #"591", #"BO", #"673", #"BN", #"61", #"CC", #"243", #"CD", #"225", #"CI", #"500", #"FK", #"44", #"GG", #"379", #"VA", #"852", #"HK", #"98", #"IR", #"44", #"IM", #"44", #"JE", #"850", #"KP", #"82", #"KR", #"856", #"LA", #"218", #"LY", #"853", #"MO", #"389", #"MK", #"691", #"FM", #"373", #"MD", #"258", #"MZ", #"970", #"PS", #"872", #"PN", #"262", #"RE", #"7", #"RU", #"590", #"BL", #"290", #"SH", #"1", #"KN", #"1", #"LC", #"590", #"MF", #"508", #"PM", #"1", #"VC", #"239", #"ST", #"252", #"SO", #"47", #"SJ", #"963", #"SY",#"886", #"TW", #"255", #"TZ", #"670", #"TL",#"58", #"VE",#"84", #"VN", #"284", #"VG", #"340", #"VI", #"678",#"VU", #"681",#"WF", #"685",#"WS", #"967",#"YE", #"262",#"YT", #"27",#"ZA", #"260",#"ZM", #"263",#"ZW", nil]; return dialCodeDict; } And then I did this : - (void)viewDidLoad { _dialCodes = [self dialCodeDict]; [self setCodes]; } - (void)setCodes{ CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new]; CTCarrier *carrier = network_Info.subscriberCellularProvider; NSArray *keys = [_dialCodes allKeys]; NSArray *values = [_dialCodes allValues]; _countries = [[NSMutableArray alloc]initWithCapacity:[_dialCodes count]]; NSString *baseCountry = [_dialCodes objectForKey:carrier.isoCountryCode.uppercaseString]; for (int i = 0; i < [_dialCodes count] ; i++){ Country *c = [[Country alloc]init]; c.isoC = [keys objectAtIndex:i]; c.dialC = [values objectAtIndex:i]; c.nameC = [[NSLocale currentLocale] displayNameForKey:NSLocaleCountryCode value:c.isoC]; c.isLocal = NO; if ([baseCountry isEqualToString:[values objectAtIndex:i]]){ c.isLocal = YES; _myCountry = c; } [_countries addObject:c]; } [_countries sortUsingComparator:^(Country *firstObject, Country *secondObject) { return [firstObject.nameC caseInsensitiveCompare:secondObject.nameC]; }]; [self.tableView reloadData]; idx = [NSIndexPath indexPathForRow:[_countries indexOfObject:_myCountry] inSection:0]; [self.tableView selectRowAtIndexPath:idx animated:YES scrollPosition:UITableViewScrollPositionMiddle]; } I think there is too much code for what you need but, what this does is fill a tableview of all countries and align the view to the current country (if the user has a sim card or an NSLocale) This is how i designed the tableview : - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier = #"InternationalCell"; CustomCellInternationalTableViewCell *cell; cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil){ [tableView registerNib:[UINib nibWithNibName:#"CustomCellInternationalTableViewCell" bundle:nil] forCellReuseIdentifier:cellIdentifier]; cell = [[CustomCellInternationalTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; }else{ cell.lbCountry.text = [[_countries objectAtIndex:indexPath.row]nameC]; cell.lbCode.text = [NSString stringWithFormat:#"+%#",[[_countries objectAtIndex:indexPath.row]dialC]]; if ([[_countries objectAtIndex:indexPath.row]isLocal] == YES){ cell.contentView.backgroundColor = FlatGray; }else{ cell.contentView.backgroundColor = ClearColor; } } return cell; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [_countries count]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ _myCountry = [_countries objectAtIndex:indexPath.row]; self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self dismissViewControllerAnimated:YES completion:nil]; } Again, there are some lines that i could remove because this is straight from my code, and because it's not well commented (my bad :D) I don't remember which would be important to you and which wouldn't ! But i'll re-read and edit if necessary.
Here is a country picker I made as a cocoapod. Usage is very simple: class ViewController: UIViewController, MRCountryPickerDelegate { #IBOutlet weak var countryPicker: MRCountryPicker! #IBOutlet weak var countryName: UILabel! #IBOutlet weak var countryCode: UILabel! #IBOutlet weak var countryFlag: UIImageView! #IBOutlet weak var phoneCode: UILabel! override func viewDidLoad() { super.viewDidLoad() countryPicker.countryPickerDelegate = self countryPicker.showPhoneNumbers = true countryPicker.setCountry("SI") } func countryPhoneCodePicker(picker: SwiftCountryPicker, didSelectCountryWithName name: String, countryCode: String, phoneCode: String, flag: UIImage) { self.countryName.text = name self.countryCode.text = countryCode self.phoneCode.text = phoneCode self.countryFlag.image = flag } }
Where is app_id value stored in xcode 6?
I've lost 2 hours searching the apple developer docs, google, and stackoverflow. Where can I find my project's app_id in Xcode 6? I am trying to adapt the apple keychain sample code https://developer.apple.com/library/ios/samplecode/GenericKeychain/Listings/ReadMe_txt.html#//apple_ref/doc/uid/DTS40007797-ReadMe_txt-DontLinkElementID_11 but I've never had to use my app_id before. Thanks for any suggestions.
Notes: When you app created in iTunes Connect, apple assigns a app_id to your APP, then you can check it in "More->About This App" Method: getSecureValueForKey Method: storeSecureValue #import "JNYJKeyChain.h" #implementation JNYJKeyChain + (NSString *)getSecureValueForKey:(NSString *)key { /* Return a value from the keychain */ // Retrieve a value from the keychain NSDictionary *result = nil; NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass, kSecAttrAccount, kSecReturnAttributes, nil] autorelease]; NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword, key, kCFBooleanTrue, nil] autorelease]; NSDictionary *query = [[NSDictionary alloc] initWithObjects: objects forKeys: keys]; // Check if the value was found OSStatus status = SecItemCopyMatching((CFDictionaryRef) query, (CFTypeRef *) &result); [query release]; if (status != noErr) { // Value not found return nil; } else { // Value was found so return it NSString *value = [NSString stringWithString:(NSString *) [result objectForKey: (NSString *) kSecAttrGeneric]]; [result release]; return value; } } + (BOOL)storeSecureValue:(NSString *)value forKey:(NSString *)key { /* Store a value in the keychain */ // Get the existing value for the key NSString *existingValue = [self getSecureValueForKey:key]; // Check if a value already exists for this key OSStatus status; if (existingValue) { // Value already exists, so update it NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass, kSecAttrAccount, nil] autorelease]; NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword, key, nil] autorelease]; NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease]; status = SecItemUpdate((CFDictionaryRef) query, (CFDictionaryRef) [NSDictionary dictionaryWithObject:value forKey: (NSString *) kSecAttrGeneric]); } else { // Value does not exist, so add it NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass, kSecAttrAccount, kSecAttrGeneric, nil] autorelease]; NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword, key, value, nil] autorelease]; NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease]; status = SecItemAdd((CFDictionaryRef) query, NULL); } // Check if the value was stored if (status != noErr) { // Value was not stored return false; } else { // Value was stored return true; } } #end
Keychain Access Not Returning kSecValueData
I'm using the following code: + (void)createKeychainItem:(NSString *)name { // Don't create if one already exists if ([self getKeychainItem:name] != nil) return; NSData *encodedName = [name dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *attributes = #{ (id)kSecAttrAccount : encodedName, (id)kSecAttrGeneric : encodedName, (id)kSecAttrLabel : name, (id)kSecAttrService : name, (id)kSecClass : (id)kSecClassGenericPassword, }; OSStatus result = SecItemAdd((CFDictionaryRef)attributes, NULL); } + (NSDictionary *)getKeychainItem:(NSString *)name { // Build the query NSData *encodedName = [name dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *query = #{ (id)kSecAttrAccount : encodedName, (id)kSecAttrGeneric : encodedName, (id)kSecAttrService : name, (id)kSecClass : (id)kSecClassGenericPassword, (id)kSecMatchLimit : (id)kSecMatchLimitOne, (id)kSecReturnAttributes : (id)kCFBooleanTrue, }; NSDictionary *output = nil; OSStatus result = SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&output); // Convert the password if it exists NSData *passwordData = [output objectForKey:kSecValueData]; if (passwordData != nil) { NSMutableDictionary *mutableOutput = [[output mutableCopy] autorelease]; NSString *password = [[[NSString alloc] initWithBytes:passwordData length:passwordData.length encoding:NSUTF8StringEncoding] autorelease]; [mutableOutput setObject:password forKey:(id)kSecValueData]; output = [[mutableOutput copy] autorelease]; } return output; } + (void)updateKeychainItem:(NSString *)name value:(NSString *)value attribute:(id)attribute { // Get the item NSDictionary *values = [self getKeychainItem:name]; // If we got nothing back, build it if (values == nil) { [self createKeychainItem:name]; } // Create a query to update NSData *encodedName = [name dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *query = #{ (id)kSecAttrAccount : encodedName, (id)kSecAttrGeneric : encodedName, (id)kSecAttrService : name, (id)kSecClass : (id)kSecClassGenericPassword, }; NSDictionary *attributes = nil; if (attribute == kSecValueData) { attributes = #{ (id)kSecValueData : [value dataUsingEncoding:NSUTF8StringEncoding] }; } else { attributes = #{ attribute : value }; } OSStatus result = SecItemUpdate((CFDictionaryRef)query, (CFDictionaryRef)attributes); } Setting a value with [self updateKeychainItem:AuthTokenIdentifer value:authToken attribute:kSecValueData]; works and I can see it in Keychain Access. Fetching the results with NSDictionary *values = [self getKeychainItem:AuthTokenIdentifer]; works, but the kSecValueData is not set in the dictionary. Everything else is set, like the create and modified dates, just not the secure data. Any ideas? This happens on iOS and Mac.
You need to use the attributes dictionary from getKeychainItem: to fetch the value. Something like NSMutableDictionary *dataQuery = [attrs mutableCopy]; [dataQuery setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData]; [dataQuery setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass]; CFTypeRef resultData; OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)(dataQuery), &resultData); NSData *tokenData = CFBridgingRelease(resultData);