Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App with Swift View Controllers and Views Frameworks and UIKit

Extending library classes anti-pattern?

This video tells about extending UIKit classes. Isn't extending framework classes considered to be an antipattern, and encapsulation the recommended approach?

2 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

No. Extending or subclassing a type from an outside framework is perfectly acceptable and a very common thing to do. I would go so far as to say it is preferred over encapsulation.

I personally don't do a lot of iOS development or use sub-classing (I use Swift for other things), so I'm not going to get into how it all works, but you might find the UIKIt documentation to be helpful.

Ok thank's, I'll prob get the picture when I proceed with the Swift courses.

It's simpler for sure to extend a class. I guess when dealing with UIKit classes there's little point in hiding any functionality since you don't typically know beforehand exactly which methods and properties you'd want? I mean, if there's a class where I want to use only a small fraction of the valuable methods & attribute, I could choose to use an interface to that utility class instead and implement only what I need.