Tag: design

typedef struct vs. Object – Benefits

I plan to define a class, that among its properties contains coordinates for an x/y grid. However, I’m unsure of the ‘best’ way to approach the design of this. It’s a very simple issue, I just want to do it correctly and have a justification! One solution would be to have to two properties, of […]

How can I differentiate the same method name of two protocols in a class implementation?

I have two protocols @protocol P1 -(void) printP1; -(void) printCommon; @end @protocol P2 -(void) printP2; -(void) printCommon; @end Now, I am implementing these two protocols in one class @interface TestProtocolImplementation : NSObject <P1,P2> { } @end How can i write method implementation for “printCommon”. When i try to do implementation i have compile time error. […]

Should my Block-based API have just completion or both success and failure handlers?

When designing a block-based API in ObjC, which approach is better, one completion block or two, one each for success and failure? Let’s say we have a method retrieving something asynchronously to a block, with one completion block it would be: – (void) retrieveSomethingCompletion:(void (^)(id retrievedObject, NSError *error))completionBlock; And with success/failure blocks (AFNetworking style): – […]

Making class conform to protocol with category for existing methods

I have a protocol named MyProtocol. MyProtocol has an required method: – (NSUInteger)length; And some other methods. Now i want to make the NSString class conform to MyProtocol with a category. Like so: @interface NSString (NSStringWithMyProtocol) <MyProtocol> @end In this category i implement all methods excluding the ‘length’ method, because i want the original NSString […]

When to use categories and when to use subclassing?

Can anybody tell me when to use categories and when to use subclassing in Objective-C? Also please tell me the advantages and disadvantages of them.

How can I prevent Xcode from doing this?

I have a lot of buttons in an app I’m making. When I select all of them, Xcode shows a dialog box saying this: Internal Error Xcode encountered an internal logic error. Choose “Continue” to continue running Xcode in an inconsistent state. Choose “Crash” to halt Xcode and file a bug with Crash Reporter. Choosing […]

Resizing an UITextView when the keyboard pops up with auto layout

I would like to resize a UITextView when the keyboard shows up but I can’t seem to do this. I’ve created a single view with an UITextView in it. In code, I would like to manually resize the height of this text view. I do this: _textView.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:_textView attribute:NSLayoutAttributeHeight […]

XCode Interface Builder: Change class of already placed object

Is there a way to do it? I want not only set Class Identity but change designed class (so object properties should change). The reason is that I placed UIView and a lot of subviews. Now I want to change it to UITableViewCell. Maybe it can be done by ‘hacking’ xib file?

Blind programmer: designing an interface in Xcode without being able to visually position UI elements

I am fairly new to Mac and iOS programming, and have recently decided to get really serious about developing applications for both platforms. The first step I took was to register to the Mac and iOS developer programs, download Xcode and study a book about Objective-C. I spent the last 6 weeks familiarizing myself with […]

Are there any good guides on custom Cocoa User Interface Design?

I’ve been a software developer (mainly Visual Studio) for many years and have been working with Objective C and Cocoa for some months now. I have a good handle now on the language and the frameworks but one thing I need to work on is interface design, more specifically custom views and tables. There is […]