use of undeclared identifier 'NSMigratePersistentStoresAutomaticallyOption' - ios5

How come I get this error when I'm declaring the code statement below?
use of undeclared identifier 'NSMigratePersistentStoresAutomaticallyOption'
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
What am I missing in order to get this to recognize my NSMigratePersistentStoresAutomaticallyOption constant?
Thanks,
Mike

NSMigratePersistentStoresAutomaticallyOption is declared in NSPersistentStoreCoordinator.h. Are you sure that that is included or forwarded wherever you're building that dictionary (like by including CoreData.h)?

Related

How to crop video into square iOS with AVAssetWriter

I'm using AVAssetWriter to record a video and I want to be able to crop the video into a square with a offset from the top. Here is my code -
NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys:
#320, AVVideoCleanApertureWidthKey,
#320, AVVideoCleanApertureHeightKey,
#10, AVVideoCleanApertureHorizontalOffsetKey,
#10, AVVideoCleanApertureVerticalOffsetKey,
nil];
NSDictionary *videoAspectRatioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
#3, AVVideoPixelAspectRatioHorizontalSpacingKey,
#3,AVVideoPixelAspectRatioVerticalSpacingKey,
nil];
NSDictionary *codecSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:bitsPerSecond], AVVideoAverageBitRateKey,
#1,AVVideoMaxKeyFrameIntervalKey,
videoCleanApertureSettings, AVVideoCleanApertureKey,
//AVVideoScalingModeFit,AVVideoScalingModeKey,
videoAspectRatioSettings, AVVideoPixelAspectRatioKey,
nil];
NSDictionary *videoCompressionSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
codecSettings,AVVideoCompressionPropertiesKey,
#320, AVVideoWidthKey,
#320, AVVideoHeightKey,
nil];
Whenever I uncomment the AVVideoScalingModeKey, the my assetWriter gives me an error about not being able to apply the videoCompressionSettings. I tried using How do make a reduced size video using AVAssetWriter? but it still didn't work for me.
I added the AVVideoScalingModeFit,AVVideoScalingModeKey to my videoCompressionSettings to get it to work.

AFNetworking - Build NSDictionary parameters

I'm trying to build my NSDictionnary to send to a request using the AFNetworking framework, but it seems that I'm quite confused about how to do it properly.
Here's what the server is expecting :
{
"limit":10,
"filters":
[
{"field":"owner","operator":"EQUAL","value":"ownerId","type":"integer"},
{"field":"date","operator":"GE","value":"30 Jun 2010 00:00:00","type":"date"},
],
"order":[{"field":"date","order":"ASC"}],
"page":0
}
What I'm trying to do (I don't really know if it's the right way to do it tbh), is to build a NSDictionary like the following :
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
#"10", #"chunkSize",
[NSDictionary dictionaryWithObjectsAndKeys:
[NSDictionary dictionaryWithObjectsAndKeys:#"owner", #"field", #"EQUAL", #"operator", #"ownerId", #"value", #"integer", #"type", nil],
[NSDictionary dictionaryWithObjectsAndKeys:#"date", #"field", #"GE", #"operator", #"30 Jun 2010 00:00:00", #"value", #"date", #"type", nil],
nil], #"filters",
[NSDictionary dictionaryWithObjectsAndKeys:
[NSDictionary dictionaryWithObjectsAndKeys:#"date", #"field", #"ASC", #"order", nil],
nil], #"order",
#"0", #"page",
nil];
But I have the following error when the view is loading :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil
I know I screw up building the parameters properly, but I can't manage to do it after several tries. Could anyone help ? Moreover, I don't really know the differences that I must implement here with the [] and the {}. I read that {} was for a dictionary and [] for an array, but I don't really see how to translate it in my case.
Your mistake is that the value for the dictionary starting on line 3 needs to be wrapped in an array.
At least until Objective-C array and hash literals go mainstream, my preferred method for creating complex dictionaries is to build them from an NSMutableDictionary. In your case:
NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionary];
[mutableParameters setValue:#"10" forKey:#"limit"];
// ...
NSMutableArray *mutableFilters = [NSMutableArray array];
NSMutableDictionary *mutableOwnerFilterDictionary = [NSMutableDictionary dictionary];
[mutableOwnerFilterDictionary setValue:#"owner" forKey:#"field"];
// ...
[mutableFilters addObject:mutableOwnerFilterDictionary];
[mutableParameters setValue:mutableFilters forKey:#"filters"];
// ...
Also, be sure you're sending that over as JSON by setting AFJSONParameterEncoding to your AFHTTPClient.
The brackets [] signify an array, while the braces {} signify an object (dictionary in this context). To produce the structure you require:
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
#"10", #"chunkSize",
[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:#"owner", #"field", #"EQUAL", #"operator", #"ownerId", #"value", #"integer", #"type", nil],
[NSDictionary dictionaryWithObjectsAndKeys:#"date", #"field", #"GE", #"operator", #"30 Jun 2010 00:00:00", #"value", #"date", #"type", nil],
nil], #"filters",
[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:#"date", #"field", #"ASC", #"order", nil],
nil], #"order",
#"0", #"page",
nil];

printing values of keys in NSDictionary

What I am having so far right now is
NSArray *keys = [NSArray arrayWithObjects:#"firstName",#"lastName",#"phoneNumber",#"email",#"password",nil];
NSArray *objects = [NSArray arrayWithObjects:#"nil",#"nil",#"nil",#"nil",#"abc",nil];
dictionary = [NSDictionary dictionaryWithObject:objects forKey:keys];
NSLog(#"pass is %#",[keys objectAtIndex:4]);
NSLog(#"value of pass is%#",[dictionary objectForKey:#"password"]);
However, What I got from the debugger is
pass is password
value of pass is (null)
Can anyone explain why the value is null.It should be abc,shouldn't it.
The following line would have given a warning:
dictionary = [NSDictionary dictionaryWithObject:objects forKey:keys];
It should read:
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
Change this line you are missing s
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
you can do it in the fallowing way also...
NSMutableDictionary *dictionary=[NSMutableDictionary dictionaryWithObjectsAndKeys:#"nil",#"firstName",#"nil",#"lastName",#"nil",#"phoneNumber",#"nil",#"email",#"abc",#"password", nil];
NSLog(#"value of pass is%#",[dictionary objectForKey:#"password"]);

Match String to ABPropertyID

I'm working now with the AddressBook and I need to convert(match) the String representation of ABPropertyID to ABPropertyID:
#"kABPersonEmailProperty" -> ABPropertyID kABPersonEmailProperty;
Can I do it flexible without using ifs?
Can I do it flexible without using ifs?
Not really. The easiest way is probably to manually prepare an NSDictionary in code that maps between the two. There is no way to do this entirely automatically because the names of the constants are not part of the compiled program.
Example:
NSDictionary *mapping = [NSDictionary dictionaryWithObjectsAndKeys:
#"kABPersonEmailProperty", [NSNumber numberWithInteger:kABPersonEmailProperty],
#"kABPersonEmailProperty", [NSNumber numberWithInteger:kABPersonBirthdayProperty],
nil];

How can I use NSDictionary's methods to add objects and keys?

I want to make an NSDictionary that has the following values where symbol & id are my keys.
I want to map "AAPL" to symbol
I want to map 100 to id.
"AAPL":symbol
"100":id
"GOOG":symbol
"101":id
"YHOO":symbol
"102":id
How can I create a dictionary of these values with
dictionaryWithObjectsAndKeys
Which one is key, which one is value? Assuming you want map symbol to id, then
NSDictionary *myDict = [NSDictionary dictionaryWithObjectsAndKeys:
#"100", #"AAPL", // 100 is object, AAPL is key
#"101", #"GOOG",
#"102", #"YHOO",
// etc...
nil];
If the IDs are numbers, use
NSDictionary *myDict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: 100], #"AAPL",
// etc...
nil];
If, OTOH, you want to map ids to symbols, then reverse the entries:
NSDictionary *myDict = [NSDictionary dictionaryWithObjectsAndKeys:
#"AAPL", #"100",
#"GOOG", #"101"
// etc...
nil];
The data you describe would most likely be represented by an array of dictionaries, since the keys would be repeated for each entry.
NSArray *array = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:#"APPL", #"symbol", #"100", #"id", nil], [NSDictionary dictionaryWithObjectsAndKeys:#"GOOG", #"symbol", #"101", #"id", nil], [NSDictionary dictionaryWithObjectsAndKeys:#"YHOO", #"symbol", #"103", #"id", nil], nil];
Assuming you want to use the ids as the keys and the symbols as the values, this should work:
NSDictionary *stocks = [NSDictionary dictionaryWithObjectsAndKeys:#"AAPL", #"100", #"GOOG", #"101", #"YHOO", #"102", nil];