objective-c

Merging NSArrays in Objective-C

I have an NSDictionary where each key points to an array. I later want to merge all of the values into one array. Is there a way to use the API to do something more efficient than say: NSArray *anArray = [someDictionary allValues]; NSArray *newArray = [NSMutableArray array]; start outter loop on anArray start inner loop on objects in...

Cocoa/Objective-C: how much optimization should I do myself?

I recently found myself writing a piece of code that executed a Core Data fetch, then allocated two mutable arrays with the initial capacity being equal to the number of results returned from the fetch: // Have some existing context, request, and error objects NSArray *results = [context executeFetchRequest:request error: NSMutableArra...

@synchronized in a static method

In Objective-C, you can declare a block as being synchronized on some object by using the @synchronized construct. It would look something like this: @synchronized (self) { // Do something useful } However, I'm curious what exactly self is referring to when you have a static method (+ instead of -). I tried looking through the App...

How to call an Objective-C Method from a C Method?

I have an Obj-C object with a bunch of methods inside of it. Sometimes a method needs to call another method inside the same object. I can't seem to figure out how to get a C method to call a Obj-C method... WORKS: Obj-C method calling an Obj-C method: [self objCMethod]; WORKS: Obj-C method calling a C method: cMethod(); DOESN'T...

Temporarily set iPhone locked wallpaper

I understand that there is no way to set a user's wallpaper, but the apple program Voice Memos temporarily changes the locked screen while recording. This lets you know that the app is still recording, and even has a little red bar at the top showing you how many seconds have passed. Is it possible for me to do this while my app is run...

objective c - call object-returning method without using return value

I know its fine to call a method as if it was void even though it has a return value (like printf), but what about this? [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(method) userInfo:nil repeats:NO]; Can I just have that floating there without using the object it returns? That's like calling [NSObject all...

Proper way to use Objective C

This isn't a style question. Its more about the proper use of the language itself. I'm am fairly new to programming and I'm totally new to Objective-C and Cocoa but after reading about the language and looking through some sample code some usage patterns continue to pop up that do not make sense to me. Or rather they seem non optimal in ...

Is this an error?

Hello, while i'm testing my app the console show: GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "sh...

Constant kCGColors deprecated on iPhone?

I'm having some trouble getting CGColorGetConstantColor() to work on the iPhone. Apple's documentation claims you can pass any of the "Constant Colors" without linking to what the Constant Colors actually are, so I assumed you can simply use those documented for OS X: CGColorRef blackColor = CGColorGetConstantColor(kCGColorBlack); Thi...

How to create an iPod-esque UISlider

Does anyone have a quick way to make a UISlider that looks like the ones in the iPod app (think scrubber/volume control). Basically I need something that looks exactly like an MPVolumeView, but doesn't control sound. Failing that, does anyone have the assets to make one (the knob/track). ...

NSString to FSRef conversion doesn't work

Hi, For my app I need to use the Carbon file manager API to get the size of a folder (NSEnumerator is slow, and using NSTask with a shell command is even worse). I've imported the Carbon framework, and I'm using this method to get the size of a folder: http://www.cocoabuilder.com/archive/message/cocoa/2005/5/20/136503 It uses an FSRef...

Objective-C modify parameter to method at runtime

I'd like to change the value of a parameter at runtime and curious how this works in Obj-C. I have a loop where value of 'n' is 0 increasing by 1 with each loop. How does one increment the passed parameter by 1 as n moves. UIViewSubclass *uiViewSubclass = [[UIViewSubclass alloc] initWithValue:([value integerValue]) ...

Accessing instance variables from UITableView delegate methods

Question: I'm trying to access a variable from the UITableView tableView:didSelectRowAtIndexPath: delegate method. The variable can be accessed from the data source methods, but when I try to access it from delegate methods such as this one, the app crashes. I declare the variable in my .h file, and initialise it in .m file in the appl...

NSString @"\" adding backslash character objective-c

Does anyone know of an easy way to add a single backslash "\" to a NSString in Objective-C? I am trying to have a NSString *temp = @"\/Date(100034234)\/"; I am able to get a double backslash or no backslash, but unable to get a single backslash. Any help would be appreciated. Thanks ...

How to make a superview intercept button touch events?

Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { // How can I get this to show up even when the button is touched? NSLog(@"%@", [touches anyObject]); } @end @interface TestViewAppDelegate : NSObject <UIAppli...

Reachability sometimes fails, even when we do have an internet connection

Hi I've searched but can't see a similar question. I've added a method to check for an internet connection per the Reachability example. It works most of the time, but when installed on the iPhone, it quite often fails even when I do have internet connectivity (only when on 3G/EDGE - WiFi is OK). Basically the code below returns NO. ...

How do you use Objective-C starting from the "Java JNI Application" template in XCode?

I want to use the NSStatusBar object from my Java application using JNI. I know there's some existing libraries out there but I've tried them and they don't have the correct drop down menu. I'm starting from the "Java JNI Application" template in XCode and I simply put NSString *str=@""; to see if it could compile but this produces ...

Using an Objective-C++ file from a C++ file

Hi. I have a c++ app that I'm trying to port to iPhone and to start off I'm trying to replace my c++ texture loader with an obj-c++ texture loader so that I can make use of the cocoa libraries. A lot of my c++ files (.cpp files) call the texture loader with something like: GLuint mTexture = TextureLoader::LoadTexture("file.png") //Load...

How to store an image using NSData in Objective C

How do I take a UIImage and store it preferably as NSData (to write to a file)? Is there some obvious method out there, or could someone provide a code snippet? Thanks in advance! PS. My next question will probably be for a code snippet to capture the current screen image. The snippets I've seen so far appear to be serious overkill f...

Custom Uisegmentedcontrol

How do I make a custom UISegmentedcontrol. I have 2 images, 1 that should be displayed when the segment is active and the other if the segment is inactive. Can i override the style or something so i have a UIsegmentedcontrol with my own images as active/inactive background? ...