Domanda

I have a Styles class that has several methods to return different font styles, colours, and object Rects (with class methods as these styles dont change) but it is getting a little messy. I would like to somehow split these methods into three different classes - Fonts, Colours, Rects but not have to import three different files into every class I use it in. Is this possible?

Currently I do [Styles heading1Font]; or [Styles blueColour]; and would like to keep doing it that way by somehow subclassing the Styles class from Fonts, etc so that it is more tidy and I dont have to import several files. It's not a huge issue if you cannot do this, I'll just have to import three different files in every class I use it unless there is a better way.

È stato utile?

Soluzione

Don't subclass, use categories. Create a single header file which defines the interface categories you want. Then create 3 different implementation (.m) files and place the methods into the appropriate category implementations.

If you want to maintain your existing files then you will need to call those methods from inside your category methods.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top