1

I'm trying to wrap my head around some of the OOP features in objective-c. It seems that using protocols is encouraged, while extending classes to add functionality is discouraged.

My problem:

I have some big chunks of code that scroll the screen when you click on a textfield. I don't want to put these huge chunks of code in every view controller. I just want to make some kind of reference to them.

Should I extend a parent class. Or use a protocol or what?

the whole protocol thing seems weird to me because it looks like it just tells you that you need to create more functions for a class without actually defining what the methods do.

I'm lost

2 Answers 2

0

I generally subclass UIViewController, put my code their, then inherit from that for the "concrete" view controllers.

But if you need to inherit from a subclass of UIViewController as well as UIViewController itself, you may want to consider putting the code in a category of UIViewController. But that also assumes that you don't need to add any property's to the class, since that is not possible in a category.

0

make them a class method by declaring them on .h file with this signature, then implementing them on .m file, with + they can be used across multiple class files, + can be thought like static method in other languages like Java

+ (return_type) someMethodName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.