objective-c

CATransaction Not Animating

I've created a new View-based Application in XCode. In the ViewController, the only code that I've modified looks like this: - (void)viewDidLoad { [super viewDidLoad]; UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; newView.backgroundColor = [UIColor redColor]; [self.view addSubview:newView]; [CATransact...

How to sort an NSMutableArray with custom objects in it?

What I want to do seems pretty simple, but I can't find any answers on the web. I have an NSMutableArray of objects, let's say they are 'Person' objects. I want to sort the NSMutable array by Person.birthDate which is an NSDate. I think it has something to do with this method: NSArray *sortedArray = [drinkDetails sortedArrayUsingSelect...

How do I draw a shadow under a UIView?

I'm trying to draw a shadow under the bottom edge of a UIView in Cocoa Touch. I understand that I should use CGContextSetShadow() to draw the shadow, but the Quartz 2D programming guide is a little vague: Save the graphics state. Call the function CGContextSetShadow, passing the appropriate values. Perform all the drawing to which you ...

Why is there no need for releasing an Outlet that's set up with "assign"?

I've been reading that if I have something like this: @property (nonatomic, assign) UIView *anView; Then I don't have to care about memory management. I don't have to do [anView release] in the -dealloc method. Why? "assign" just tells the compiler: "Hey man, this property does not retain whatever anyone assigns to it". And then you...

Launch Image

I managed to design a fairly decent launch image/default.png. But I noticed that it just flashes for a second then goes to the UI. Is it possible to code the launch image and make it dynamic? Remaining on screen until the user touches it or a button. Or is this something one would definitely not want to do? Thanks, ~D1~ ...

Toll free bridges

As a newcomer to iPhone development and Objective-C in general over the last few weeks I have come across numerous mentions of 'Toll free bridges' between CF and NS frameworks. One particular example would be CFStream and NSStream. Does a resource exists documenting all of these bridges and how to use them ? Is it just as simple as cas...

Is there anything like 'getStreamsToHost' on real iPhone device?

I want to write an NSOutputStream to a server with apple's sample code: NSURL *website = [NSURL URLWithString:str_IP]; NSHost *host = [NSHost hostWithName:[website host]]; [NSStream getStreamsToHost:host port:1100 inputStream:nil outputStream: [oStream retain]; [oStream setDelegate:self]; [oStream scheduleInRunLoop:[NSRunLoop currentRu...

What's the difference between @property and @synthesize?

Like I understand, @synthesize actually is generating the Getters and Setters. But what's @property then doing? Is it just setting up the parameters for that cool @synthesize magic function? ...

Naming conventions for BOOL Obj-C 2 properties?

I have a readonly BOOL property. What is dominant naming pattern here? Background: for plain old method declarations, the accepted pattern - (BOOL)isEditable; - (void)setEditable:(BOOL)flag; In a @property world, that would typically be expressed as @property(getter=isEditable) BOOL editable; However, there are examples to the con...

UIButton: Making the hit area larger than the default hit area.

Hello, I have a question dealing with UIButton and it's hit area. I am using the Info Dark button in interface builder, but I am finding that the hit area is not large enough for some people's fingers. Is there a way to increase the hit area of a button either programmatically or in Interface Builder without changing the size of the I...

UILabel: Using the userInteractionEnabled method on a label

Hello again. I am wondering if anyone has used the userInteractionEnabled method on a UILabel to allow the label to act like a button (or just to fire off a method). Any help would be greatly appreciated. Cheers! Update (4/30/09 @1:07pm) Clarification: I have a standard InfoButton and next to it I want to place a label with the text...

Link to a constants file in Cocoa / Xcode

In reference to this related question on stackoverflow: If you create a constants file, how do you "link" to it in your target, so you don't have to #import "Constants.h" in every file you use constants? ...

When do you use encodeWithCoder: and initWithCoder: on the iPhone?

As my question in the subject above states, what requirements do you typically have to meet in order to say "Ok, I need encodeWithCoder: and initWithCoder: instantiation for this"? Typically you can write object state to NSUserDefaults, so I'm curious when do you experts decide to use one vs the other? ...

NSUserDefaults: Dumping the structure of NSUserDefaults's standardUserDefaults

Hi hi. Does anyone know of a quick way to dump the standardUserDefaults of NSUserDefaults via NSLog? This is what I have: NSLog(@"NSUserDefaults dump: %@", [NSUserDefaults standardUserDefaults]); But it returns: NSUserDefaults dump: <NSUserDefaults: 0x50b520> ...which is not quite what I'm looking for. I'd really like to have ke...

NSNumberFormatter only rounds to 3 decimal places

Hi, I'm trying to use NSNumberFormatter to round a number to 5 decimal places in an iPhone app, but [formatter stringFromNumber:] always returns strings rounded to 0.001 (3 decimal places). What am I doing wrong??? Many thanks. formatter = [[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterDecimalStyle]; [forma...

Releasing UIViewController when its view is removed via removeFromSuperview

I have a main view that manually creates a UIViewController (not a UINavigationController) and adds that controller's view as a subview. The subview then dismisses itself via [self removeFromSuperview]. I understand this releases the view, so that is good, however I now want to get also get rid of the UIViewController I alloc'ed immedia...

Get image from a video frame in iPhone

Is it possible using the iPhone SDK to grab a frame from a video in iPhone and save it or use it in any way in the application? Does the SDK give any control over the video other than play/stop or maybe access to the binary data of the video? Also is it possible to know the time at which the user stopped watching the video (i know in SD...

How can I add a C-based language to GCC

If I wanted to modify or add my own extensions to C, and add them to the GCC C compiler, what would I need to do? I do not want to propose changes to the language, I want to know how the C compiler actually works. I've had a look at the source code to GCC and it looks as if Objective-C is implemented as a simple parser that generates co...

Why does a Convencience Constructor or Object Factory have to care about releasing the Object?

Actually, if you use a method with "new", "create", "alloc" or "copy" in it's name, then you are responsible for releasing the object that is returned to you. BUT: Why do these methods make an call to -autorelease? Wouldn't this result in "over-releasing" the object? Lets say I get that object from such a method, and then I call -releas...

Is it right to say that methods whoose names contain new, alloc, create or copy do not autorelease the objects they create?

As far as I know, only the "convenience" methods return created objects with an -autorelease, so that the receiver is not responsible for the memory of that object. But because Apple says that when you use a method that has a name consisting of "new", "alloc", "create" or "copy", you're responsible for releasing the object that method re...