objective-c

@synthesize-ing a C array of structs in Objective-C 2.0

I'm trying to follow a tutorial for a C++ interface in the Mac OS X API (Audio Queue Services), but in a Cocoa (well, actually just Foundation) application (well, actually just a 'tool'). It has a struct that looks like this: static const int kNumberBuffers = 3; // 1 struct AQPlayerState { AudioStreamBas...

Objective-C Singleton instance as a static?

In Apple's documentation for their example of a Singleton, and I do understand there's more than one way to skin a cat -- but why do they bother ensuring the instance is registered as static? Take from: http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_10.html I'm referring to: ...

Difference between inheritance and Categories in Objective-c

Can some one explain to me the difference between categories and inheritance in Objective C? I've read the entry in wikipedia and the discussion on categories there doesn't look any different to that of inheritance. I also looked at the discussion on the topic in the book "Open Iphone Development" and I still don't get it. I might be mi...

Use C++ with Cocoa Instead of Objective-C?

Hi. I would like to write applications that use C++ and the Cocoa frameworks because Apple are not making Carbon 64-bit capable. C++ seems to be pretty vanilla in it's implementation on Linux and Windows but on Mac OS X it seems like additional Apple specific pieces of code are required (like an Obj-C wrapper). It also seems that Apple a...

Xcode complier warning "assignment from distinct objective-c type"

I'm learning objective-c, working through Aaron Hillegass' book "Cocoa Programming for Mac OS X - Third Edition". I'm working in Xcode to develop some of the example code, and keep getting a compiler warning on the last line of this method: - (void) setEntryDate:(NSCalendarDate *) date { [date retain]; [entryDate release]; e...

Objective-C pointers?

Hi, I am new to coding and trying to get up to speed with Objective-C. Came across some code I did not understand. I was hoping someone could clarify it for me. In the case below, I am not sure how *foo2 is working and why it is not being released? ClassOne *pointer = [[ClassOne alloc]init]; ClassTwo *foo = [[ClassTwo alloc]init], *fo...

Is if (variable) the same as if (variable != nil) in Objective-C

I am getting a EXC_BAD_ACCESS (SIGBUS) on this line in my iPhone project: if (timeoutTimer) [timeoutTimer invalidate]; The thing that has me stumped is that I don't understand how that line could crash, since the if statement is meant to be checking for nil. Am I misunderstanding the way Objective-C works, or do line numbers in crash ...

Best way to learn Objective-C

I would like to learn Objective-C using online tutorials. I'm a native C# programmer but I know C++. Which compiler should I use on windows vista? ...

iPhone different between self and normal variable

HI all, What is difference betwin self.myVariable = obj and myVariable = obj, when i use @propery/@synthesize for it ...

In Objective-C what is the equivalent of the java "instanceof" keyword?

I would like to be able to check the type of an object ...

Xcode String Format Error

Hi There, When debugging the following code NSString *var1 = @"blaa"; NSString *var2 = @"blaaaaa"; NSString* script = [NSString stringWithFormat:@"Set_Variable( %s, %s )",var1,var2]; the %s placehoders in script are replaced with funny gibberish characters. Can you see any errors in the code. Many thanks, (Confused .NET developer tr...

How to message superview in Objective C

Hello. I am new to Objective C and Cocoa. I just don't get it how to message the superview of an UIView. I can't get it work. Here is what i tried so far: In my MainView i have a method named resetDrawType: - (void) resetDrawType { self.drawType = foo; } Also in the MainView i create a subview and add it to MainView: mySubView *m...

Memory management. Is this single line of code correct?

Do I have a leak with this statement? //Pass the copy onto the child controller self.childController.theFoodFacilityCopy = [self.theFoodFacility copy]; My property is set to: @property (nonatomic, retain) FoodFacility *theFoodFacilityCopy; The reason I think I have a leak is because copy retains the value and then my dot syntax prop...

Constants in Objective C

I'm developing a Cocoa app, and I'm using constant NSStrings as ways to store key names for my preferences. I understand this is a good idea because it allows easy changing of keys if necessary. Plus, it's the whole 'separate your data from your logic' notion. Anyway, is there a good way to make these constants defined once for the whole...

Objective-C : BOOL vs bool

Hi, I'm new to Objective-C and I saw the "new type" BOOL (YES, NO). I read that this type is almost like a char. For testing I did : NSLog(@"Size of BOOL %d", sizeof(BOOL)); NSLog(@"Size of bool %d", sizeof(bool)); Good to see that both logs display "1" (sometimes in C++ bool is an int and its sizeof is 4) So I was just wondering ...

Apple's Singleton example

Used the MyGizmoClass example in a iPhone app where I have an object that sets and maintain db info. How do I eliminate the 'MyGizmoClass' may not respond to '+sharedManager' Warning The offending line of code is: NSString *databasePath = [[MyGizmoClass sharedManager]databasePath]; ...

Explanation of Cocoa @selector usage.

I'm new to Cocoa/Cocoa Touch, and working through a development book. I've come across situations where the @selector() operator is used. I'm a bit lost on how and when the @selector() operator should be used. Can someone provide a short and sweet explanation and example of why it's used and what benefit it gives the developer? By th...

Is there a Mac emulator or Objective-C environment I can run on Windows?

I'm in the process of learning Objective-c but would like to run code snippets via some sort of emulator on Windows — preferably web based. I want to understand Objective-C syntax and walk through common code examples, probably via some sort of console. I would probably leave any framework type learning for when I get onto my MacBook,...

Objective-C memory management, xml parser and other non-trivial examples.

I know the basic principles about memory management (retain count, autorelease pools etc) in Cocoa, but once you go past simple retain/release, it's getting a bit more confusing. I couldn't find decent answers for those, as most tutorials cover simple scenarios. I would like to ask about best practices in how to write the code and avoid ...

initializing a class. Can you see any problems with this?

-(id)init { if (self = [super init]) { self.name = [[NSString alloc] init]; self.type = [[NSString alloc] init]; self.phoneNumber = [[NSString alloc]init]; self.webAddress = [[NSString alloc] init]; NSMutableArray *pricesArray = [[NSMutableArray alloc] init]; NSMutableArray *poolsArray = [[NSMutableArray alloc] init]; self.pric...