objective-c-category

Is this a sane Objective-C Block Implementation?

青春壹個敷衍的年華 提交于 2019-12-18 17:07:15
问题 I wanted a variation of NSRegularExpression's – stringByReplacingMatchesInString:options:range:withTemplate: method that takes a block instead of a template. The return value of the block would be used as the replacement value. This is more flexible than a template, as you can imagine. Sort of like using the /e modifier in Perl regular expressions. So I wrote a category to add the method. This is what I came up with: @implementation NSRegularExpression (Block) - (NSString *

Is this a sane Objective-C Block Implementation?

时间秒杀一切 提交于 2019-12-18 17:06:08
问题 I wanted a variation of NSRegularExpression's – stringByReplacingMatchesInString:options:range:withTemplate: method that takes a block instead of a template. The return value of the block would be used as the replacement value. This is more flexible than a template, as you can imagine. Sort of like using the /e modifier in Perl regular expressions. So I wrote a category to add the method. This is what I came up with: @implementation NSRegularExpression (Block) - (NSString *

How to call original implementation when overwriting a method with a category?

扶醉桌前 提交于 2019-12-18 13:34:30
问题 I try to figure out how things really work. So I thought when I would overwrite certain methods using categories, I would get interesting NSLogs. @implementation UIView(Learning) - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { NSLog(@"-hitTest:withEvent: event=%@", event); return [self hitTest:point withEvent:event]; } @end super and self don't work here. Is there a way to call the original implementation of -hitTest:withEvent:? What I want is an NSLog every time -hitTest

When to use categories and when to use subclassing? [closed]

大城市里の小女人 提交于 2019-12-17 21:58:08
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . Can anybody tell me when to use categories and when to use subclassing in Objective-C? Also please tell me the advantages and disadvantages of them. 回答1: An objective-c category is useful if you want to alter the behavior of ALL instances of the class, with minimal code.

How to implement a custom color method into code

倖福魔咒の 提交于 2019-12-13 05:15:55
问题 I have created a class containing code for a "customColor" that I want to implement into my code so that I can just type buttonOne.backgroundColor = [UIColor customColor] . In the .h file, I have + (UIColor*) customColor; and in the .m file, I have + (UIColor*) customColor { return [UIColor colorWithRed:0.643 green:0.643 blue:0.643 alpha:1]; } but when I go to "ViewController.m" and type in buttonOne.backgroundColor = [UIColor customColor] I get an error saying No known class method for

Objective-C: Make private property public with Objective-C category

只谈情不闲聊 提交于 2019-12-13 04:20:14
问题 I am looking for a way to make a private property (declared in .m file within class extension) public so that it is accessible outside the class, without changing its original class . Is there any way to accomplish this, possibly via Objective-C category? I see from Apple documentation that category can be used, although not recommended, to redefine methods already in the original class, but I'm not sure if it can be used to make "existing" properties available to other classes. 回答1: This is

Objective C: how to inherit category methods loaded in a parent class?

只愿长相守 提交于 2019-12-12 21:45:47
问题 In my project, I am using the NSObject+Properties.h category (see aqtoolkit: https://github.com/AlanQuatermain/aqtoolkit/blob/master/Extensions/NSObject%2BProperties.h) I then have a class that I declare as #import <Foundation/Foundation.h> #import "NSObject+Properties.h" @interface GFDictionaryInitiable : NSObject ... I then have several subclasses of GFDictionaryInitiable , such as GFRestaurant : #import <Foundation/Foundation.h> #import "GFDictionaryInitiable.h" @interface GFRestaurant :

Is it possible to define a property with Class type that conforms to protocol?

戏子无情 提交于 2019-12-12 15:08:31
问题 For example, I have MyFancyData protocol. How can I specify that MyFancyDataClass property accepts only classes that conforms to this protocol. @interface MyObject : NSObject @property Class MyFancyDataClass; 回答1: @property id<MyFancyData> myFancyDataClass; 回答2: Do you mean something like this? @interface MyObject : NSObject @property (nonatomic, assign) Class<MyFancyData> cls; @end 来源: https://stackoverflow.com/questions/27760662/is-it-possible-to-define-a-property-with-class-type-that

Objective-C Category Performance

若如初见. 提交于 2019-12-12 11:42:51
问题 If I used categories to break up the implementation of my Objective-C class into multiple @implementation blocks, would that make the resulting binary of my iOS app larger or affect performance at all? Apparently, you can't Obtain details of categories on a class at runtime?. So, shouldn't the resulting binary be identical with or without categories, assuming all else equal? Background I have a custom subclass of UIViewController that's getting rather complex. iOS Developer Library :

How Do I Know Which Methods to Override When Writing an Objective-C Category?

白昼怎懂夜的黑 提交于 2019-12-12 02:39:21
问题 I want to write a category on UINavigationItem to make changes to barBackButtonItem across my entire app. From what I have been told in the comments here ( Change BackBarButtonItem for All UIViewControllers? ), I should "override backBarButtonItem in it, then your method will be called whenever their back bar button item is called for." - but how do I know what method to override? I have looked at the UINavigationItem documentation, and there are multiple methods used for initializing a