objective-c-category

How a class extension works as a means of implementing private methods

≯℡__Kan透↙ 提交于 2019-12-06 06:25:06
I believe a popular way to declare "private methods" in Objective-C is to create its class extension and declare methods that you would like to make as private. I would like to know more in detail on how an class extension makes the methods work as private. Update: I asked this question with the term empty category which is incorrect. I now changed it as class extension That's not an "empty category", it's a class extension . Read Bbum's explanation of them at the link I provided. That's because you create your empty category in your implementation file, not your header file so other classes

Category Conflict: instance method in category from conflicts with same method from another category

帅比萌擦擦* 提交于 2019-12-04 16:21:15
问题 There are two situations, that I am aware of, that cause the following errors: ld: warning: instance method 'resetAudioSystem' in category from /opentok-ios-sdk/Opentok.framework/Opentok(OTPublisher+AudioSnoop.o) conflicts with same method from another category ld: warning: instance method 'attachAudioSnoopBlock:' in category from /opentok-ios-sdk/Opentok.framework/Opentok(OTPublisher+AudioSnoop.o) conflicts with same method from another category ld: warning: instance method

Advice on how to catch “attempt to insert nil object” from a device needed

谁说胖子不能爱 提交于 2019-12-04 12:43:37
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 and use method swizzling for collection classes. Say, I'll replace insertObject:atIndex with my

Duplicate symbol error when adding NSManagedObject subclass, duplicate link

青春壹個敷衍的年華 提交于 2019-12-03 18:32:36
问题 I was trying to create NSManagedObject subclasses (2 related entities) automatically in Xcode. They are generated like this: However, before I do anything further, when I tried to build and run it, a link error occur, as shown: duplicate symbol _OBJC_CLASS_$_Photo in: /Users/Kefeng/Library/Developer/Xcode/DerivedData/Photomania-aellrakjngugnzcgrleiytvrfvyt/Build/Intermediates/Photomania.build/Debug-iphonesimulator/Photomania.build/Objects-normal/x86_64/Photo+CoreDataClass.o duplicate symbol

Facebook iOS SDK 3.2.1 - [NSError fberrorShouldNotifyUser]: unrecognized selector sent to instance

…衆ロ難τιáo~ 提交于 2019-12-03 16:46:07
问题 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 instance This 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

Adding the same category to multiple classes

浪子不回头ぞ 提交于 2019-12-03 15:04:09
问题 I have an Objective-C category that I'd like to add to multiple classes without duplicating the code contained in the category. I simply want to add the same methods to multiple classes. I have existing categories on NSManagedObject subclasses ( Book , Chapter , Page ) and I would like to add common functionality throughout these subclasses in a clean and maintainable way. One way would be to add the category to their common superclass ( NSManagedObject ), but that has the consequence of

Category Conflict: instance method in category from conflicts with same method from another category

孤者浪人 提交于 2019-12-03 10:24:12
There are two situations, that I am aware of, that cause the following errors: ld: warning: instance method 'resetAudioSystem' in category from /opentok-ios-sdk/Opentok.framework/Opentok(OTPublisher+AudioSnoop.o) conflicts with same method from another category ld: warning: instance method 'attachAudioSnoopBlock:' in category from /opentok-ios-sdk/Opentok.framework/Opentok(OTPublisher+AudioSnoop.o) conflicts with same method from another category ld: warning: instance method 'setVideoSnoopDelegate:' in category from /opentok-ios-sdk/Opentok.framework/Opentok(OTPublisher+VideoSnoop.o) conflicts

CocoaPods UIImageView+AFNetworking.h unrecognized selector setImageWithURLRequest

房东的猫 提交于 2019-12-03 07:11:46
I have installed AFNetworking 2.1.0 with CocoaPods on Xcode 5. //ViewController.h #import <AFNetworking/AFNetworking.h> #import <AFNetworking/UIImageView+AFNetworking.h> Calling setImageWithURLRequest on an UIImageview the application fail with this log: This is the error log: 2014-02-07 11:55:19.984 OPS[1717:60b] *** Terminating app due to uncaught exception'NSInvalidArgumentException', reason: '-[UIImageViewsetImageWithURLRequest:placeholderImage:success:failure:]: unrecognized selector sent to instance 0x147b06d0' I've found some discussion on this issue, but the provided solution (adding

How can I declare a private property within a named category?

好久不见. 提交于 2019-12-03 02:38:55
I know about the possibility of declaring private properties on a class by putting them inside an unnamed category on that class declared in the implementation ( .m ) file of that class. That's not what I want to do. I'm dealing with a named category on a class that adds some functionality to that class. For this functionality, it would help me very much to have a private property to use in my category - so the usual way of achieving this (described above) doesn't seem to work for me. Or does it? Please enlighten me! Inside your category's implementation file, declare another category and call

What's the difference and use of categories and inheritance? [duplicate]

浪子不回头ぞ 提交于 2019-12-03 01:06:22
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Difference between inheritance and Categories in Objective-c When should I use subclassing and when should I use categories? 回答1: Subclass when you want to extend the functionality utilized by the base. @interface MyObject: NSObject<SomeProtocol> Add a category when you want to add a convenience method to code you may not control. @interface UIView (MyViewAdditions) - (void)recursiveEnumerateSubviewsUsingBlock: