|
I use a collection of category methods for Cocoa's built in classes to make my life easier. I'll post some examples, but I really want to see what other coders have come up with. What kind of handy category methods are you using?
Example #1:
@implementation...
Started by e.James on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
}
This provides a method to easily get dates like "9am the day:0];
Category, which adds ....
This is self-explanatory:
-(BOOL)isOnTheSameDayAsDate:(NSDate isOnTheSameDayAsDate:anotherDate]) { ...
I have a few nifty methods on NSDate.
|
|
I have a products table that contains a FK for a category, the Categories table is created in a way that each category can have a parent category, example:
Computers Processors Intel Pentium Core 2 Duo AMD Athlon
I need to make a select query that if ...
Started by Bruno on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
I suppose there's no limitation to the category hierarchy depth....
I have done similar things in the past, first querying for the category ids, then querying you want to find is the transitive closure of the category "parent" relation.
|
|
Style-wise (and functionally, if there is any difference), for declaring private methods, which of these is better?
@interface MyClass() @interface MyClass(private)
Started by Elliot on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
If you declare a private category on your own class (Private) category can exist....
methods in the main @implementation block for the corresponding class; anonymous categories allow you/category named pairs must be unique.
|
Ask your Facebook Friends
|
When using categories, you can override implementation methods with your own like so:
// Base Class @interface ClassA : NSObject - (NSString *) myMethod; @end @implementation ClassA - (NSString*) myMethod { return @"A"; } @end //Category @interface ClassA...
Started by Kendall Helmstetter Gelner on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
When a category implements a method which has already is launched."
From developer.apple.com : "When a category overrides an inherited method, the method, if a category....
But certainly some problems will be caused.
|
|
I am using Three20 for the iphone and I am trying to change what a method does within it by using a class category. It compiles fine, but I never reach the break point in it.
I'm assuming a class category affects all instances of the class, so I don't...
Started by Brenden on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Alternatively....
Can only add methods:
Although the language currently allows you to use a category to overrideWhen two categories override the same method on the same class in the same binary, it isn't defined the method on that.
|
|
Hello folks,
I was reading how to implement private methods in Objective-C ( Best way to define private methods for a class in Objective-C ) and a question popped up in my mind:
How do you manage to implement protected methods, i.e. private methods that...
Started by Lio on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Alternatively, you could declare the Protected ....
For this, the writer of a subclass must be informed in some way about the protected methods, and they will need to put up with the compiler warnings.
To simulate protected methods as well.
|
|
I have a SELECT statement that works, and runs fast enough on my tables (<0.01sec on 50k+ products, 3k+ categories). But in my mind it's not very elegant and would like to hear any suggestions on making it better.
There are 3 tables of interest:
products...
Started by rwired on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Left join the ones you don't want and check for null)
I can think of a few methods, each of which.
|
|
I've got the following tables:
Products: id, name, ... Products_in_Categories id, category_id, product_id Categories id, name, ...
I have an admin page where I want to let him search products by name, catalog id etc. And of course by category and name...
Started by OfficeJet on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
JOIN Categories c ON c.id = pc.categroy_id WHERE c.name = 'CATEGORY A'
you also don't need to have a id in the Products_in_Categories table since the combination of category_id and product_id is unique_CATEGORY_NAME....
|
|
If a category I'm creating for a class adds methods that also fulfill the contract set out by a protocol, I'd like to flag that category class as implementing the protocol, and thereby indicate to the Obj-C pre-processor that the class effectively implements...
Started by Justin Searls on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
That's where the warnings are coming from because now your category does instead.
And implement the method in a different category, e.g.:
@interface NSObject (SomeCategory) <SomeDelegate> SomeDelegate <NSObject> ...
|
|
I'd like to override a method in an Objective C class that I don't have the source to.
I've looked into it, and it appears that Categories should allow me to do this, but I'd like to use the result of the old method in my new method, using super to get...
Started by Brad Parks on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
There's an article on Theocacao written by Scot Stevenson about Method Swizzling in the old Objective-C runtime, Cocoa....
But be aware that your code could break something.
What you want is called Method Swizzling .
Find the method.
|