objective-c

The best way to remove duplicate values from NSMutableArray in Objective-C?

The best way to remove duplicate values (NSString) from NSMutableArray in Objective-C? Is this the easiest and right way to do it? uniquearray = [[NSSet setWithArray:yourarray] allObjects]; ...

how to add and remove UIToolbaritems programatically?

I want to add and remove the items on UIToolbar at runtime. Is there any way to do that? ...

How can you allocate a class in objective-c where the class name is an NSString?

Hi! I've got a PHP background, but I'm beginning to learn Objective-C, so that I can develop apps for the iPhone. So far things are going pretty well, but I've got a question that I haven't been able to find and answer to yet after googling and mining a number of different forums. My app has to create a number of views, each with it's o...

Filling a shape with a gradient in CGContext

I want to fill a polygon shape that I have drawn via Core Graphics with a linear CGGradient. The CGContextDrawLinearGradient function draws a gradient from one point to another but it fills the entire view. How can I display the gradient only inside the polygon shape I have drawn? ...

What's the standard convention for creating a new NSArray from an existing NSArray?

Let's say I have an NSArray of NSDictionaries that is 10 elements long. I want to create a second NSArray with the values for a single key on each dictionary. The best way I can figure to do this is: NSMutableArray *nameArray = [[NSMutableArray alloc] initWithCapacity:[array count]]; for (NSDictionary *p in array) { [name...

Getting NSArrayController item for right click in NSCollectionView

Hello, I'm trying to create a file explorer using nscollectionview and am currently implementing a right click menu for each item (i.e. copy/delete/rename/etc). I currently have: An NSCollectionView linked with an NSArrayController which holds a custom object A subclass of NSBox as the view for each item, this also tracks mouse events...

how to stream internet radio on iphone?

Any one know how I can stream internet radio on iPhone with code? Is a provider required? ...

How to dynamically add transparency to iPhone image?

Suppose I have image canvas or previously loaded image which supports transparency (gif/png). What are the steps to implement changing transparency for the image, but not for the whole image, but only a part of it? I undestand I should use CGContext, but i'm lacking the details. ...

Read file into array

I have a file of words/phrases separated by newlines. I need to get the file and read each word/phrase into the array. I have this so far: NSFileHandle *wordsFile = [NSFileHandle fileHandleForReadingAtPath:[[NSBundle mainBundle] pathForResource:@"WordList" ofType:nil]]; NSData *words = [w...

How can I set the default state of a UISegmentedControl?

Is there a way to set the starting selected segment in a UISegmentedControl in Interface Builder, or do I have to do it in the code? If it's in the code, is viewDidLoad the best place to set it? ...

Access NSArray from a NSTimer Interval = EXC_BAD_ACCESS

I have some code that looks like this: actualColor = 0; targetColors = [NSArray arrayWithObjects:[UIColor blueColor], [UIColor purpleColor], [UIColor greenColor], [UIColor brownColor], ...

How can I make an iPhone app that responds to the OnRing event?

I want to write a iPhone application, it needs to react to the onRing event (or whenever someone calls, regardless of their ring/vibrate settings). Is this possible? Would my application have to be running all the time or can it just run during a ring? (it is a light application, not sure how long it will take to load up though). I bas...

Override ringer volume in iPhone apps

I have built an app that plays lots of sounds the easy way: AudioServicesPlaySystemSound(someSoundID); When I use the device volume buttons to increase or decrease the volume, the volume I actually change is the phone's ringer volume. So if you decrease it and exit the app then your phone will ring quietly... Is there an easy way to ...

Obj-C: C functions declared inside or outside @implementation block, what's the difference?

what's the difference between a C function (static or not) declared inside or outside the implementation block (@implementation ... @end) of a Objective-C class? is this specially true?: If you need to poke inside of the object directly, you can put this function inside of the @implementation block of your class, and then you can ac...

CoreAnimation Game - Adding a video feed as the background?

Greetings Friends, I am trying to overlay the simple 2D game I am developing on top of a quicktime (.mov) movie. I do not have experience with this (or much game programming xp) so I'm wondering if anyone has had to deal with this problem before and, if so, how did you go about solving it? I've been looking into the QuickTime API (QTKi...

Core Data: Strange bindings error on re-opening a document. Help?

Hi, I have been building a core data application to administrate some data and I've been stumped by a bug that indicates my objects aren't KVO compliant. However, I haven't modified the default KVO compliance of the NSManagedObject, and now I'm left scratching my head. The area of the application that the bug is affecting is that of cre...

Is there anything that makes memory management easier for iPhone/iPod Touch application programming?

I've only used Java and Ruby for so long that I'm really not enjoying keeping track of my own memory again. It's not that I can't do it, I can. I just don't want to. Any special tricks, libraries, or anything else you've learned for dealing with memory in iApps, lay it on me here. ...

Singleton Design

I'm creating a game that uses cards. I have an AppController class with one instance in the nib. The AppController instance has an NSArray instance variable called wordList. On init, the nib's instance of AppController generates a new GameCard. Every gamecard has an array of words containing 5 words selected at random from the the list i...

Why do unimplemented optional protocol methods cause runtime errors when that method is called in obj-c?

I have two classes that can act as a delegate of a third class, and both implement a formal protocol made entirely of optional methods. One of the classes implements everything while another only implements a couple methods that i care about. However, at runtime when i have the second class act as the delegate to the third class, and t...

Should I connect my iPhone app directly to a web service or proxy through my own site?

What's the best approach for using a web service in an iPhone app? Should I connect directly to the service or proxy the request through my own web server and where I can cache the results and, if the service changes, make any updates in a single location without having to have my app update approved by Apple. ...