I want to use this for an object factory: Given a string, create a Class, and if this Class supports a protocol (with a Create() method) then alloc the class and call Create.
Objective C : Given a Class id, can I check if this class implements a certain protocol? Or has a certain selector?
21.9k Views Asked by Jacko At
2
There are 2 best solutions below
Related Questions in OBJECTIVE-C
- How do I customize NSOutlineView to have border color?
- UIWebView Screen Fitting Issue
- How to hide "Now playing url" in control center
- CloudKit: Preventing Duplicate Records
- Image and Text locations in UIButton
- setting OpenGL version in objective-C
- Setup code for xibs in iOS. -awakFromNb:
- realm db, get parent link of object
- CFBundleDocumentType is not working in myproject-Info.plist file
- UIPopoverPresentationController not rendering properly
- Using Storyboard Reference
- Pass Data between two view controllers using 'Delegation' : Objective-C
- Unexpected CALayer Vertical Flipping on 3D Rotation 'Bounce'
- Setting View orientation to portrait is ignored
- UITextField append / between dates while enforcing character limit
Related Questions in CLASS
- Access objects variable & method by name
- Pass variables to extended class
- Threading Segfault when reading members
- __PHP_Incomplete_Class Object even though class is included before session started
- How to declare a class with a constructior outside of a function C++
- ClassCastException: datastructures.instances.JClass cannot be cast to java.util.ArrayList
- Java: set and get methods for strings
- Allow extension of class by injection of user-made subclass, while preserving accessibility
- Efficiency penalty of initializing a struct/class within a loop
- Possible to add a new class that can be cast to an existing final class?
- introduce c++ into html
- how can Object class in ruby be an instance of it's subclass, class "Class"
- Class enumerator values cannot be passed as parameters to another class's function
- Passive Objects in C++
- open class or implicit class in java
Related Questions in PROTOCOLS
- Objective-C Reference to object that implements protocol
- Declare conditional delegate methods in iOS
- Object initialization with protocol and class name in swift
- How to get file path in browser (using protocol or other method to get full path)
- call generic function without params
- Why do we send the length of a string in most of the currently protocols
- How to cast controller to a specific protocol instead of a class in Swift?
- Extending Swift's Dictionary to conform to Protocol that requires the use of subscript causes Linker Error
- Benefit of class inheritance, when you could use protocol extensions?
- NSObject class conforms to protocol contained in NSArray with Swift
- Assigning a variable from another class
- Swift protocol extension self reference issues with init
- Swift - Delegates - How do I link the protocol to the implemented delegate methods?
- How to hide the class' properties and methods when defining and using one protocol in the .h file for Objective-C?
- Configure asio context to use tls
Related Questions in OBJECTFACTORY
- Orika - Determining constructor call without registering an ObjectFactory
- Object Factory with limited base class
- Using custom ObjectFactory with JAXB: is there an established "go to" pattern?
- C++ object factory with built-in cache - shadows template parameter
- How do I generate multiple .xsd's into the same ObjectFactory?
- How to map an attribute of Type Object in ORIKA
- c++11 singleton of a derived class with an abstract factory
- C++ preventing user from creating object instances
- What is the ObjectFactory role during JAXB-Unmarshalling?
- Android: class file for javax.naming.spi.ObjectFactory not found - when I tried to integrate Hessian into Android
- Specify a `DataSource` factory instead of Tomcat's default
- Objective C : Given a Class id, can I check if this class implements a certain protocol? Or has a certain selector?
- How to generate several versions of Java classes generated by JAXB?
- How To Use ObjectFactory Generated By Jaxb?
- How to create dynamic instance when java web service client class exist with version number?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
May I, however, point out just how many awful Objective-C rules you're breaking by doing the above? For example, you should never be calling methods on an allocated-but-not-initialized instance. The Xcode Static Analyzer will give you all sorts of warnings about memory leaks.
A better option would be this:
But you seem to imply that you don't want to call init.
You could consider a class method:
[klass create], which would return a non-owned instance ofklass. Then you'd just check[klass respondsToSelector:@selector(create)]before calling it.