Category that stubs out enough of UITextView to allow categories upon it to be speced with cedar. See this thread on the Cedar mailing list for more info
Created
October 19, 2010 01:53
-
-
Save wezm/633459 to your computer and use it in GitHub Desktop.
Category that stubs out enough of UITextView to allow categories upon it to be speced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| @interface UITextView (Spec) | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* This category attempts to stub out UITextView to allow categories upon it | |
| to be tested. Specifically the following error is being avoided: | |
| Tried to obtain the web lock from a thread other than the main thread or the | |
| web thread. This may be a result of calling to UIKit from a secondary thread. | |
| Crashing now... | |
| */ | |
| #import "UITextView+Spec.h" | |
| static NSMutableDictionary *attributes__; | |
| // Overrides to allow UITextView categories to be tested | |
| @implementation UITextView (Spec) | |
| + (void)initialize { | |
| attributes__ = [[NSMutableDictionary alloc] init]; | |
| } | |
| - (id)initWithFrame:(CGRect)frame { | |
| if (self = [super initWithFrame:frame]) { | |
| CFDictionaryAddValue((CFMutableDictionaryRef)attributes__, self, [NSMutableDictionary dictionary]); | |
| } | |
| return self; | |
| } | |
| - (NSMutableDictionary *)attributes { | |
| return [attributes__ objectForKey:self]; | |
| } | |
| - (void)dealloc { | |
| CFDictionaryRemoveValue((CFMutableDictionaryRef)attributes__, self); | |
| [super dealloc]; | |
| } | |
| #pragma mark Property overrides | |
| - (void)setFrame:(CGRect)frame { | |
| } | |
| - (void)setText:(NSString *)text { | |
| [self.attributes setObject:text forKey:@"text"]; | |
| } | |
| - (NSString *)text { | |
| return [self.attributes objectForKey:@"text"]; | |
| } | |
| - (void)setSelectedRange:(NSRange)range { | |
| NSValue *value = [NSValue valueWithRange:range]; | |
| [self.attributes setObject:value forKey:@"selectedRange"]; | |
| } | |
| - (NSRange)selectedRange { | |
| NSValue *value = [self.attributes objectForKey:@"selectedRange"]; | |
| return [value rangeValue]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment