problem about objective-c-category-Collection of common programming errors
Halle
cocoa naming-conventions objective-c-category
I’ve stumbled into one of two classic programming problems. I’m writing a Cocoa framework which is basically a collection of (mostly) helpful methods in categories of the most-used Foundation classes. My question is how do I name these extra methods in my categories for said classes? Should I go with a prefix or prefix-less naming convention (e.g. – (void)doSomething vs – (void)myDoSomething)?I became unsure when reading the Cocoa documentation:Use prefixes when naming classes, protocols, functi
doctordoder
objective-c nsmutablearray protocols objective-c-category
I don’t think I’ve found an example quite like my own on this site even though I’m sure this pops up all the time, and I just finished a chapter on this subject in my book.I’m not looking for anything complicated, but I just want to add some functionality to NSMutableArray for objects that are of a certain type because I don’t want to subclass NSMutableArray because it seems too difficult, but I may change my mind about that.I want a category that offers NSMutableArrays that conform to the NDVec
Eonil
objective-c subclassing objective-c-category
Category methods added to specific class doesn’t work at its subclass.For me, I’m using JSONKit to manipulate JSON. JSONKit returns JKArray subclassing NSArray. And I have several methods added to NSArray. But when I execute my program, unrecognized selector sent to instance runtime exception thrown with the method.How can I use the category method?
Cirrostratus
python prototype extend objective-c-category
I’d like to add functionality to the set data type of Python. In Objective-C I might use a category like so:@implementation Set (CirrostratusAdditions) – (Set *)modifiedSet;{return self;} @endOr in JavaScript like so:Set.prototype.modifiedSet = function(){};Is it possible to append functionality to existing classes in Python. If so, what is this concept called within Python runtime and where might I best get acquainted with the concept?
chaiguy
objective-c class-method objective-c-category
AFNetworking has a class method called + af_sharedImageCache that I want to access from my own category, but I can’t figure out the syntax to reference this. Internally it is doing [[self class] af_sharedImageCache] but obviously that’s not gonna work for me. 🙂
Anoop Vaidya
objective-c ios polymorphism objective-c-category
Possible Duplicate:What happens if two ObjC categories override the same method? I have two Categories on NSString class as follows://first category#import “NSString+MyCategory1.h”@implementation NSString (MyCategory1)-(void)myMethod{NSLog(@”this is my method from category 1”); }@end//second category#import “NSString+MyCategory2.h”@implementation NSString (MyCategory2)-(void)myMethod{NSLog(@”this is my method from category 2”); }@endBut the following main method is always calling myMethod from
Stephen Cross
ios objective-c uitextview objective-c-category
I’ve had working code for categories of UITextField and UITextField similar to the following on iOS5 and iOS6 devices. However, the UITextView category method does not appear to be called on an iOS7 device (an iPhone5S). The code is:@interface UIView (CustomCategory) -(void) someCategoryMethod; @end@implementation UIView (CustomCategory) -(void) someCategoryMethod {NSLog(@”UIView category methods appear to work.”); } @end@interface UITextField (CustomCategory) -(void) someCategoryMethod; @end@im
rnk
java objective-c ruby objective-c-category
I am trying to draw parallels between Objective-C Category and features in Java and Ruby. Please see if these conclusions are accurate – Objective-C Category adds new methods to an existing class even when you do not have access to source code of the class. Java does not have anything similar but in Ruby you can “open” any class, including core language class like String. class String def my_new_method”new test method”end end”some string”.my_new_method => “new test method”Similarly in Objecti
Unheilig
ios objective-c metaclass objective-c-runtime objective-c-category
I understand a class is actually an object / typedef of struct (objc_class*). Each class has a “backing” meta class, which in turns has a isa pointer pointing to the meta class of NSObject. And NSObjectbasically has a isa pointer pointing back to itself.And we could get a hold of the meta class via this line:objc_getMetaClass(“<CLASS_NAME>”);I hope my understanding of meta class is not off here so far (please correct me if it is).My questions are:1.) When would we need to deal with meta cl
Simon
objective-c objective-c-category
I want to add some methods to subclasses of NSManagedObject that implement the SOManagedObject protocol. I’ve tried defining it like this:@interface NSManagedObject <SOManagedObject> (MyExtensionMethods)… @end…but that doesn’t seem to be valid. How do I define a category that adds methods to classes which implement a particular protocol?
Peter DeWeese
objective-c objective-c-category
I have a set of data classes that I’d like to extend with my own methods by creating categories unique to each class.When declaring a category, does each category need to have a unique name, or can I reused the same name.Example. Say I have a List class and ListItem class and I want categories on both. What I’m doing now is declaring as follows:In List+Additions.h@interface List (Additions) …In ListItem+Addtions.h@interface ListItem (Additions) …Is that ok? I can’t tell if its consistently w
Heath Borders
objective-c xcode linker objective-c-category
I have a category that I import in a .m thusly:#import “UIView+Additions.h”If I forget to add UIView+Additions.m to my target, I won’t know until runtime when the runtime can’t find my selector. Is there a way to find out at compile time (or probably link time) that I forgot to include a category’s implemtation?
Anoop Vaidya
objective-c objective-c-2.0 objective-c-category
I am trying to call a method from another class which is in another source file. Example:I have a file named Source1.h/Source1.m (both are objective C class files) I have another file names Source2.h/Source2.m (both are objective C class files) Source1 contains 2 methods eg: method1 and method2. From Source2 file, I need to call the method1 from source1 file.I know how to do that in objective C. But in my source2 file, the method names in Source1 will be retrieved dynamically. I am not going to
Dale Emery
objective-c ios objective-c-category
Is there a way to add a category to a class whose header file you can’t access?For testing purposes, I want to add a category to UITableViewCellDeleteConfirmationControl, but the class is (as far as I can tell) part of a private framework.How can I do that?Elaboration (per mihirios’s request):I am trying to extend the Frank testing framework to simulate tapping the confirmation button (the big red “Delete” button) that appears when you try to delete a UITableViewCell. Frank adds a tap method to
openfrog
objective-c ios xcode objective-c-category
I’m trying to add “properties” to categories using associate objects API.objc_setAssociatedObject(self, &kIsAnimatingAssocObjKey, animating, OBJC_ASSOCIATION_RETAIN_NONATOMIC);Xcode complains: Implicit declaration of function ‘objc_setAssociatedObject’ is invalid in C99andUse of undeclared identifier ‘OBJC_ASSOCIATION_RETAIN_NONATOMIC’Xcode 4.5.2, iOS SDK 6 with deployment target 6. It does not work.None of the articles on obj_assoc mention that I must import anything special.
chm052
objective-c runtime objective-c-category flexible memory-efficient
Is it:For memory efficiency from not having to store all the program’s methods in RAM all the time? If so, is this really that common a problem? I feel like the overhead of having to load a new method would cancel out the memory savings for normal-sized programs, although I can see how it would help for something very large.For increased flexibility? If so, could you give have an example of that? I’m finding it difficult to think of one.I have been trying to Google out the answer to this questio
kraftydevil
ios interface-builder uibarbuttonitem objective-c-category unrecognized-selector
My iOS app crashes when pressing a button found in a custom view for the rightBarButtonItem. A custom view is used because the barButtonItem design requires more than just a button.Here is the output of the crash:[UIViewControllerWrapperView buttonPressed:]: unrecognized selector sent to instance 0x7669430] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[UIViewControllerWrapperView buttonPressed:]: unrecognized selector sent to instance 0x7669430’The custom
dariaa
ios objective-c runtime objective-c-category swizzling
Here is a situation: Hockeyapp and testflight every now and then complain about me “attempting to insert nil object”in mutable dictionaries/arrays. I know the right thing is to check for nil all the time, and I do when it makes sense.. Our testers can not catch those crashes, but AppStore users obviously can.My guess is that sometimes server returns NSNulls when it should not. So not to insert checks for nil everywhere in the huge project my idea was to create a separate target for the testers
Dfowj
objective-c uinavigationbar objective-c-category
I have a category on UINavigationBar, the drawRect function of which draws a custom logo in the nav bar. There is one view controller in my app which i would not like to draw the custom logo for. Is there a way to bypass the category’s drawRect function?
zavié
ios objective-c singleton nscalendar objective-c-category
We are using dateFromComponents: to parse a date string returned from Server. In rare cases this call crashes, but we couldn’t reproduce the bug. Has anyone seen this kind of stack trace?Thread 0: 0 libicucore.A.dylib 0x3b13514e _uprv_asciitolower + 18 1 libicucore.A.dylib 0x3b18757b _uloc_openKeywordList + 291 2 libicucore.A.dylib 0x3b135d7f _uloc_getName + 15 3 libicucore.A.dylib 0x3b135ba7 __ZN3icu6Locale4initEPKca +
Ollie177
iphone ios6 uiimage nsdata objective-c-category
I have made a UIImage Objective C catagory to house this function:#import “UIImage+fixOrientation.h”@implementation UIImage (fixOrientation)- (UIImage *)fixOrientation {// No-op if the orientation is already correctif (self.imageOrientation == UIImageOrientationUp) return self;// We need to calculate the proper transformation to make the image upright.// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.CGAffineTransform transform = CGAffineTransformIdentity;switch (self.
Anoop Vaidya
ios objective-c objective-c-category
I have the following problem that I do not succeed to solve. Your help will be appreciated.To calculate a md5 from a NSS tring, a category has been defined by :NSString-md5.h@interface NSString (MD5) – (NSString *)MD5String; @endNSString-md5.m#import <CommonCrypto/CommonDigest.h> #import “NSString-md5.h” @implementation NSString(MD5) – (NSString *)MD5String{isconst char *cstr = [self UTF8String];unsigned char result[16]; CC_MD5( cstr, strlen(cstr), result );return [NSString stringWithFo
workInAFishBowl
iphone ios linker-error objective-c-category
I’ve run into an issue with linker errors that I can’t seem to solve or find the reason for problem. I added a Category to my iOS project, called ParentViewController+CoreData. I didn’t add anything to this category in either the .h or .m file, but if I import it into another file I get 35 linker errors. ParentViewController is a view controller in my code that I would like to make a category for. If I make a category from a standard view controller, I have no issues. I’ve made categories from c
abroekhof
objective-c cocoa objective-c-category scripting-bridge
I am trying to write a category over iTunesTrack with associated objects (an NSMutableDictionary and an NSNumber)#import “iTunes.h” #import <objc/runtime.h>@interface iTunesTrack (dictionary) – (NSMutableDictionary*) getDictionary; – (NSNumber*) getScan; – (BOOL)scanTrack:(NSString *)equationString; @endThis fails:Undefined symbols for architecture x86_64:”_OBJC_CLASS_$_iTunesTrack”, referenced from:l_OBJC_$_CATEGORY_iTunesTrack_$_dictionary in iTunesTrack+dictionary.o ld: symbol(s) not fo
Josh Caswell
objective-c methods override objective-c-category
This question already has an answer here:Overriding methods using categories in Objective-C2 answersI understand that overriding a method by using a category is a discouraged practice. Nonetheless, I have to deal with some code that does this. When I ran the following code, I was initially surprised that my category method was called in both cases, though thinking about how the linker must have to make a decision at link time for any given symbol made me feel better about it. My question: Assumi
Joe
objective-c objective-c-category
Say I have a class Parent and the child is Child1 and Child2.I declare Parent+ParentCategory and then I declare a method:-(void) Redraw;Later I want the Redraw function of Child1 to be different than the Redraw function of Child2.Can I declare Child1+Child1Category and then override the -(void) RedrawCan -(void)Redraw of Child1 call the function in the parent category?Can that be done?What would be good approach?I know classes can inherit each other. I know protocol can extend each other. I wond
Forrest
ios subclass objective-c-category
Category is alternative of subclassing. What will happen if the category message already has been implemented in the class. Take UIViewController as example,@implementation UIViewController (Landscape) // Override to allow orientations other than the default portrait orientation. – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {// Return YES for supported orientations.return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrie
cskoala
iphone ios objective-c objective-c-category
When you implement a category of a class in a file, will all the instances of that class be of the category by default?I’m new to Objective-C and I’m trying to make my uneditable UITextView non-selectable. I came across this answer using a category: http://stackoverflow.com/a/8013538/1533240Which has the following solution:@implementation UITextView (DisableCopyPaste)-(BOOL) canBecomeFirstResponder {return NO; } @endI added the snippet to my code, but it doesn’t seem to be working in that I can
Joe Rideout
ios runtime-error facebook-ios-sdk objective-c-category
I just upgraded my app from Facebook iOS SDK 3.1 to 3.2.1 and I’m trying to take advantage of the new error handling provided by the new FBError category on NSError. The code is at the bottom. It compiles fine, but when a FB error occurs, I get the following at run time:- [NSError fberrorShouldNotifyUser]: unrecognized selector sent to instanceThis seems like a linker error, where the category is not getting linked in from the the FacebookSDK static library. I tried adding both the -ObjC and -al
Web site is in building