Im getting this annoying error and tried every i know but in this case it hasnt helped.
I have in my delegate....
vid_name = [push objectForKey:#"vid"];
(in the console .... vid = "video" )
now in my normal page i have
NSString *videoName = [(MissileAppDelegate *)[[UIApplication sharedApplication] delegate] vid_name];
NSString *path = [[NSBundle mainBundle] pathForResource:videoName ofType:#"mp4"];
when i run this and it comes to play the video, i get an error that doesnt even relate to the video, it happens with all variables i try and pass over using the [push objectForKey:#"vid"];. if i just vid_name =#"video" it works fine.
Any Ideas?
Alex
First of all do not name your variables like vid_name! You should always use vidName in Objective-C.
You should share more information, I'm not really getting what you're doing and the error message you get would be niche.
But It sounds like a memory management problem. Because when you use the #"video" this is a static string that is always there. But when you use objectForKey: you get an object that is autoreleased and get's eventually deallocated at some point. So make sure your vid_name still exists when accessing it from your 'normal page'.
Cocoa Memory Management Programming Guide
Related
So my code works for about 90% of people. The rest get a crash at launch. I figure with all the memory I'm tying up here, this is the problem?
Maybe i shouldn't use an array as such?
for(i=60;i<80;i++){
myNewString = [NSMutableString stringWithFormat:#"%i", i ];
if (finchKeys[i]==nil)
finchKeys[i] = [[Sound alloc] initWithFile:
[[NSBundle mainBundle] URLForResource:myNewString withExtension:#"wav"]];
}
Is there something I can call to free up memory before I load my wavs?
thanks!!
I imagine you're not playing all of the wavs at once. Why not just save the wav url in your Sound class instead of the whole wav? Then you can just load each wav when you need to play it.
I'm implementing a manually-triggered migration process for a CoreData-based app, and after the migration completes successfully, I'm trying to move the migrated DB back over the top of the original one using replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:.
The problem is that on iOS, nothing I do will make this method return YES, however it also never puts anything into the error pointer to allow you to see what's going wrong.
I'd read things elsewhere (e.g. http://www.cocoabuilder.com/archive/cocoa/287790-nsdoc-magic-file-watcher-ruins-core-data-migration.html) indicating that not shutting down all the CoreData objects (e.g. NSMigrationManager, NSManagedObjectModel etc) before attempting the replace might be the cause, but that wasn't it. I even implemented a little two file create-and-swap thing that didn't involve CoreData DBs at all to verify that the CoreData stuff didn't have anything to do with it.
I then noticed in the official documentation that the newitemURL is supposed to be in a directory deemed appropriate for temporary files. I assumed that that meant a directory returned by URLForDirectory:inDomain:appropriateForURL:create:error: using NSItemReplacementDirectory as the search path.
That didn't work either! I ended up falling back to implementing the replacement logic using separate operations, but this is non-atomic and unsafe and all that bad stuff.
Does anyone have a working snippet of code that runs on iOS that either return YES from a call to replaceItemAtURL or actually puts error information into the error pointer?
Any help much appreciated.
EDIT - Test code included below. This runs in application:didFinishLaunchingWithOptions: on the main thread.
NSFileManager *fm = [[NSFileManager alloc] init];
NSError *err = nil;
NSURL *docDir = [NSURL fileURLWithPath:[self applicationDocumentsDirectory]];
NSURL *tmpDir = [fm URLForDirectory:NSItemReplacementDirectory
inDomain:NSUserDomainMask
appropriateForURL:docDir
create:NO
error:&err];
NSURL *u1 = [docDir URLByAppendingPathComponent:#"f1"];
NSURL *u2 = [tmpDir URLByAppendingPathComponent:#"f2"];
NSURL *repl = nil;
[fm createFileAtPath:[u1 path]
contents:[[NSString stringWithString:#"Hello"]
dataUsingEncoding:NSUTF8StringEncoding]
attributes:nil];
[fm createFileAtPath:[u2 path]
contents:[[NSString stringWithString:#"World"]
dataUsingEncoding:NSUTF8StringEncoding]
attributes:nil];
BOOL test = [fm replaceItemAtURL:u1 withItemAtURL:u2 backupItemName:#"f1backup"
options:0 resultingItemURL:&repl error:&err];
// At this point GDB shows test to be NO but error is still nil
I have experienced issues with all the NSFileManager methods using an URL on iOS. However, all the methods using Path work. So I think you should use removeItemAtPath:error:and copyItemAtPath:toURL:error: for that purpose.
Hope it helps
In mac file system is not case sensitive, but in IOS it. Even though you cant have two files with same name but with different case at one location, the path is case sensitive. So if file is has .JPEG and in your code you are passing link with .jpeg it will fail.
It may not be the case with you but just what to share
Although strangely it should give you error.
I'm in deep trouble. Something in my app causes a lot of properties in my app delegate to become trashed (changing contents and even object type, say an NSArray becomes an NSString...), and I can't debug it out. I can find no memory leaks or errors on my part. The only thing I've found is that all the way to ViewDidAppear for the view of the first tab, everything is okay. The view displays a table. When one of the cells are clicked, the app delegate properties are already trashed.
What after a view has been loaded and before didSelectCellForRow could cause this? No other code of mine is being executed between those two, certainly no code in the app delegate.
Any tips for hunting this down in an sleuthy manner would be appreciated, or just some thoughts on narrowing it down to what could cause it.
It sounds like either something is getting released prematurely or things are not properly connected with respect to one of your XIBs. If you haven't already, you might want to familiarize yourself with NSZombieEnabled, NSDeallocateZombies, NSEnableAutoreleasePool and NSAutoreleaseFreedObjectCheckEnabled. These are environment variables that can be set in the Executable "Get Info" window's Arguments panel.
For sanity's sake, I have added this to my AppDelegate's -applicationDidFinishLaunching:
#ifdef DEBUG
// account for environment value's actual value if set.
NSString *NSZombieEnabled = (getenv("NSZombieEnabled"))
? [NSString stringWithCString:getenv("NSZombieEnabled") encoding:NSASCIIStringEncoding]
: #"NO";
DLog(#"NSZombieEnabled = %#", NSZombieEnabled );
NSString *NSDeallocateZombies = (getenv("NSDeallocateZombies"))
? [NSString stringWithCString:getenv("NSDeallocateZombies") encoding:NSASCIIStringEncoding]
: #"NO";
DLog(#"NSDeallocateZombies = %#", NSDeallocateZombies );
NSString *NSEnableAutoreleasePool = (getenv("NSEnableAutoreleasePool"))
? [NSString stringWithCString:getenv("NSEnableAutoreleasePool") encoding:NSASCIIStringEncoding]
: #"YES";
DLog(#"NSEnableAutoreleasePool = %#", NSEnableAutoreleasePool );
NSString *NSAutoreleaseFreedObjectCheckEnabled = (getenv("NSAutoreleaseFreedObjectCheckEnabled"))
? [NSString stringWithCString:getenv("NSAutoreleaseFreedObjectCheckEnabled") encoding:NSASCIIStringEncoding]
: #"NO";
DLog(#"NSAutoreleaseFreedObjectCheckEnabled = %#", NSAutoreleaseFreedObjectCheckEnabled );
#endif
It sometimes saves me from having to check these variables through Xcode UI.
The only way out was to wade through every alloc in the app delegate and a few viewcontrollers and also made sure I knew what'd happen using the NSCopying protocol. There were 2 errors due to synthesized but nil (and then reassigned!) objects, and 1 copy-error, one or more of them caused the trashing when there was an early "autorelease" by Objective-C.
I am encountering an issue while posting a variable with Xcode:
While running this code the app crashes while posting the variable to a webservice:
NSArray *array = [stringFromFile componentsSeparatedByString: #","];
NSString *time = [array objectAtIndex:1];
UTCorLocal = time;
NSLog(#"%#", UTCorLocal);
UTCorLocal variable is declared earlier in the code. The NSLog outputs the correct string, but when I try to use it further along in the code it crashes.
When I give the variable a static value like this:
UTCorLocal = #"UTC";
It all runs like it should do!
Could anybody please help, it's driving me crazy!
Thanks a lot,
Ron
It's probably released somewhere along the way, I would guess, without knowing the rest of your code. Try copying or retaining 'time' and see what happens.
I have a strange behave:
After making a few changes in my code, I got an unasked URL in the NSURL. Actually, this URL was valid in a test I made yesterday, but the system remembers this URL and I cannot changed it even in another app.
When I strted a new app with the followung code:
int main(int argc, char *argv[]) {
NSURL *URLurl = [NSURL URLWithString:#"http://www.google.com"];
NSLog([URLurl absoluteString]);
}
the baseUrl is something like: http:inl.co.il, even I asked for google.com,
the NSLog is correct and prints: http://www.google.com
But it does not help me since the base is what the entire code works with.
And strangly, where from is that NSURL taking this old unused string?
Any help?
Thank you
Never log variables directly inside of NSLog like this, as any percent symbols will easily cause mayhem. Instead do:
NSLog(#"%#", [URLurl absoluteString]);
Lacking further information, this is probably the root of the problem. Also, the compiler should be warning you your original statement is dodgy, anyway.