objective-c

Objective-C basics: subclassing and member variable accessability

Hi, Code below is pseudo code. Imagine a class "Fruit" which has a factory method to create a fruit. interface Fruit { } +(Fruit*) createFruit: { return [[Fruit alloc] init autorelease]; } Now I want to subclass the Fruit to get an Apple: interface Apple : Fruit { int iSeeds; } +(Apple*) createAppleWithColor: (int) iSeeds { Apple*...

How to populate AudioStreamBasicDescription for AMR playback

source data is AMR-NB 5.9kbit/s (AMR_5.90) I've tried the below settings (and a dozen variations) but I'm getting nothing more than garbage audio. Does anyone know the correct settings for AMR? AudioStreamBasicDescription asbd; asbd.mSampleRate = 8000.0; asbd.mFormatID = kAudioFormatAMR; asbd.mFormatFlags = 0; asbd.mBytesPerPacke...

getting the same value in each cell of table view in objective-c.

i have check by printing the value of the cell.textlable.text in each iteration of the loop each time the value of it is as i want, but as the time of output on the simulator the value is come same for each row of cell. my code: for(i=0;i<[appDelegate.books count];i++) { Book *aBook= [appDelegate.books object...

Why the macros in Objective-C / Cocoa?

I'm coming from a place without macros (Java/Python/C#/Scala) so perhaps my perspective is distorted but... Why are macros used in Cocoa? Two that spring to mind are NSLocalizedString and NSAssert (and STAssert). Would it be so hard / unsuitable to make them functions (which could be inlined)? I suppose I find them a little bizarre as a...

Using SecKeyRawSign on the iPhone

I'm trying to sign some data using SecKeyRawSign but I keep getting a -4 errSecUnimplemented. That seems strange since the documentation states that it is available in iPhone OS2.0 and later. Has anyone been able to use this function? If so, are there any tricks involved? ~Nate ...

Localized Duration as NSString. (Cocoa)

Hi, I know if want to display a date, that Objective-C has methods to convert the date as a string to the current locale settings. Is there an equivalent for durations? I mean something like 00:12:34 (0 hours, 12 minutes and 34 seconds) in different locales? ...

How to make the UIWebView render the standard version of a webpage instead of automatically being redirected to the mobile version?

The server in some ways redirecting all the request into its mobile version, in which it lacks information, I want to render the page in the standard version using the UIWebView. What would I have to do? I have tried to set the "User-Agent" of the NSURLMutableRequest to Safari but it does not work. Any ideas why? NSMutableURLRequest *mu...

OCUnit testing an embedded framework

UPDATE: I ended up giving up and added GHUnit to my project instead. I got up and running with GHUnit in a matter of minutes. UPDATE: You can download the Xcode project here: http://github.com/d11wtq/Cioccolata I've added a Unit Test target to my Xcode project but it fails to find my framework when it builds, saying: Test.octest could...

Rendering hundreds of "block" images -vs- Partially rendering a "map" of blocks

It seems that none of these solutions eliminate the lag associated with rendering images onto the screen (whether from .png's or using CG). There is a 28x16 grid of blocks that are each 16x16 pixels, and at some points in the game, about half of them need to change their image because of a state change. Having each block as a subview of...

High level process of extracting images from a container

Right, this is the problem I have a container (rar,zip) which contains images png's tiffs bmps or jpegs in an order. The file extension isnt zip or rar though but uses the same compression. I want to pull out a list of images contained within the file in the numerical order, then depending on the user decision go to the image selected....

Making classes work together in obj-C

I'm writing a program for iPhone that will first let the user take a photo, then will dynamically retrieve a colour of the place where the user taps on the image, and draw a rectangle of that colour. I have two relevant classes for this: AppViewController and AppView. The former contains all the UI elements and IBActions, the latter the ...

initWithCoder breaking my touch events (touchBegan, touchMoved, etc)

So I have a UIView that has been setup, and in each touch event handler I have an NSLog fire off a message to the console. - (void) touchesBegan:(NSSSet*)touches withEvent:(UIEvent*)event { NSLog(@"touchesBegan"); } And that pretty much works as expected. But once I implement initWithCoder (even blank) - (id)initWithCoder:(NSCode...

Global NSMutableArray doesn't seem to be holding values

I have a Cocos2D iPhone application that requires a set of CGRects overlaid on an image to detect touches within them. "Data" below is a class that holds values parsed from an XML file. "delegateEntries" is a NSMutableArray that contains several "data" objects, pulled from another NSMutableArray called "entries" that lives in the appli...

Make "page-turning" transform (3D) follow x-axis

Hello I'm making an eBook reader for the iPhone. I have made a page-turn with CABasicAnimation and it's working great. Now I want to do the page-turn "manually" by using the x-coordinate when your finger moves along the screen. I've achieve that, but it needs some tweaking to feel more "real". Because of the 3D effect (defined by transf...

XCode - Linking Tests with Sources without adding all source files to the Test Task.

In Xcode, when source and test classes in are different folders - In the 'Test' task - how do you link against the source, as opposed to adding the all source files to the test task ? ...

How to download files directly to disk on the iPhone os?

Hi, I would like to download files directly from an URL to the disk using objective-c on the iPhone os. Currently I am using NSURLConnection to send a synchronousRequest, writing the returned NSData into a file. How can I change the download handling (still having the request beeing synchronous, it is already in a background thread) t...

Inserting a line break from a variable objective c

I am pulling data into my iphone application using xml. The xml value is then placed in a variable. example variable: 123 London road \n London \n England The variable is then set as a label. I want the line breaks to appear in the label, instead it is printing \n. If i manually set the label value locationLabel.text = @"123 Lo...

How do I convert an NSMutableString to NSString when using Frameworks?

I have written an Objective-C framework which builds some HTML code with NSMutableString which returns the value as an NSString. I have declared an NSString and NSMutableString in the inteface .h file: NSString *_outputLanguage; // Tests language output NSMutableString *outputBuilder; NSString *output; This is a sample from th...

XCode - Run Focussed Test

In XCode - Is there a way of running just one test(one test case or preferably one test method). What I do today is to run the 'Test' task which runs all tests and takes up a lot of time. Thanks ...

what does "+" means in Objective-C files

Hey all, I've been reading some Obj-C projects, and I'm always finding this standard for naming files: ClassName+OtherClassName.h What does this mean? Normally is used with a base class used on the left side, and another class used on the right side, like: NSString+URLEncoding.h Thanks in advance. ...