objective-c

why does this code leak? (iphone)

This is the header: @interface ForumBrowserAppDelegate : NSObject <UIApplicationDelegate> { ForumSelection *forumSelection; UIWindow *window; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet ForumSelection *forumSelection; (I'm not sure what the nonatomic does, is it something to do w...

MPMoviePlayerController problem at start

Hello guys! I have a problem with MPMoviePlayerController, because when I start it in fullscreen it exists, but the song is still playing. I added the MPMoviePlayerDidExitFullscreenNotification notification and it says that when the video starts playin it exists the full screen. Here's my code: _multimediaPlayer = [[MPMoviePlayerContro...

'Calling a method' OR 'sending a message' in Objective C

In C or any ECMAscript based language you 'call a public method or function' on an object. But in documentation for Objective C, there are no public method calls, only the sending of messages. Is there anything wrong in thinking that when you 'send a message' in ObjC you are actually 'calling a public method on an Object'.? ...

Using ideas from Uncle Bob's Clean Code in real-world code

I just finished reading the "Functions" chapter from Uncle Bob's Clean Code. The main advice was to make sure that functions are short -- really short. And they should only do one thing per level of abstraction. Here's a function from an app I'm making to learn Cocoa (idea from Andy Matuschak). - (IBAction)go:(id)sender { NSString *outp...

UIImagePickerController causing sqlite errors (Simulator only)

When I display a UIImagePickerController in a UIPopoverController the console outputs the following warnings: sqlite error 8 [attempt to write a readonly database] sqlite error 8 [attempt to write a readonly database] sqlite error 8 [attempt to write a readonly database] sqlite error 1 [no such column: duration] sqlite error 1 [no such ...

Fetch DB File From Server and use the SQL C API to work with file at run-time.

I realize that I can't write to the app bundle at runtime. I had originally thought I could simply download a file to the application bundle which would in turn be read by my application. NSURL *url = [NSURL URLWithString:@"http://www.drewcarpenter.info/shopping.db"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [re...

Suppressing line specific XCode compiler warnings

Similar to Ben Gottlieb's question, I have a handful of deprecated calls that are bugging me. Is there a way to suppress warnings by line? For instance: if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden:withAnimation:)]) { [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:U...

Returning NSNull from actionForLayer:forKey

If I implement the CALayer delegate method actionForLayer:forKey I can return [NSNull null] to force the CALayer to not animate any changes. Unfortunately, [NSNull null] doesn't implement the CAAction delegate and XCode kicks out the following warning: warning: class 'NSNull' does not implement the 'CAAction' protocol Here is the m...

How do I pass a value to a method in Objective C

I'm new to Obj-C and I have run in to a very, very basic mental block that's making me feel a little stupid. I want to pass a variable from one method to another in an purely objective-C way. So far I'm stuck and have resorted to writing it in C. In C it goes as follows; //detect the change in the segmented switch so we can; change tex...

Is there a concise way to map a string to an enum in Objective-C?

I have a string I want to parse and return an equivalent enum. I need to use the enum type elsewhere, and I think I like how I'm defining it. The problem is that I don't know a good way to check the string against the enum values without being redundant about the order of the enums. Is there no option other than a big if/else? typedef ...

Alternative for didSelectRowAtIndexPath when UITableViewCells are UIResponders?

The cells in my tableview are horizontal UIScrollViews, which I assume is the reason didSelectRowAtIndexPath is not being called. I have my resignFirstResponder call in that method. Does anyone have an easy way for me to fix this? Is there an alternative to didSelectRowAtIndexPath? Or is there a way to get that method to fire? Thanks!...

SQLite3 DB File On Server - How Can I Use in Objective-C?

I would like for my iPhone application to interact with a sqlite3 database file that is hosted on my server. How can I achieve this with Objective-C? Let me know if you need more details. ...

How do I share an NSArrayController between two nib files?

I have an array of images, and two nib files. One nib file has a window that displays the images in an NSTableView. The other nib has a window that draws the array of images into an NSView, and also draws a highlight over the images that are selected. The array of images is controlled by an NSArrayController. I'm having trouble getting ...

Array of Objects

Complete and utter neophyte to Objective-C and the entire Mac platform so don't flame me please =). Basically I'm trying to create a simple game. The game has a board which I've created a class for and a board is comprised of squares which I also created a class for (board and square respectively). In my view controller I'm trying to ...

iphone nsarray problem?

Okay maybe i just need another set of eyes on this, but I have the following lines of code in one of my view controllers. It takes some data from a file, and populates it into an array using "\n" as a separator. I then use that array to make an NSDictionary, which is used to populate a tableview. It's very simple. However it isnt working...

Serialize struct with pointers to NSData

Hey guys, I need to add some kind of archiving functionality to a Objective-C Trie implementation (NDTrie on github), but I have very little experience with C and it's data structures. struct trieNode { NSUInteger key; NSUInteger count, size; id object; __strong struct trieNode ** children; __strong struct trieN...

"out of scope" error when iterating an NSMutableArray

Why am I getting an "out of scope" error whenever I try to access the "url" variable in this loop? for(NSString *url in self.winnerImageURLs) { [mediaItemString appendFormat:@"{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"},", url, url]; } The class of very item in the "self.winnerImageURLs" NSMutableArray comes back a...

Size already defined

I was messing with my Objective-C++ namespace today. I found that Handle, Size and Duration are already defined in ObjC++. What are they defined to be and where are they defined? I have only #imported Foundation/Foundation.h ...

How to avoid "incomplete implementation" warning in partial base class

I have created a protocol that my classes need to implement, and then factored out some common functionality into a base class, so I did this: @protocol MyProtocol - (void) foo; - (void) bar; @end @interface Base <MyProtocol> @end @interface Derived_1 : Base @end @interface Derived_2 : Base @end @implementation Base - (void) foo{ //...

How can i get the correct date?

Hi, I have a time of NSString type. i wonder get the day, but i find somethine strange. NSString *strTime = @"2010-05-14 16:00:01"; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *oldDate = [formatter dateFromString:strTime]; unsigned int flags = NSYearCal...