1

Hello I have been looking around for this answer and I've come across multiple articles but none of them have given me a straight answer. Lets say we have Object Date in objective C if I want to add methods to this object I would create a file similar to this:

obj c:

@interface Date (AdditionDate)
//methods
@end

in swift it seems to be a little different we do the following:

extension Date {
//methods
}

is this correct? Thank you for your help!!

1 Answer 1

2

Yep that's correct. What you are looking for is called a category in Objective-C terminology. It is the ability to add on methods to an existing class even if you don't have the original source code for that class. Keep in mind that you can't use categories to store any state on the original object, so instance variables are off the table.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome thank you so much for the explanation! this answers my question!

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.