How to export headers from private Cocoa framework? - objective-c

There is a framework at
/Applications/Xcode.app/Contents/OtherFrameworks/DevToolsCore.framework
and I was wondering if it's possible to get the header information somehow?
It's a framework that theoretically allows to create plugins for XCode.
The header looks like this
and I can't access the headers as usual with public frameworks. But there has to be a way, because I found some resources online that list the classes, but the class descriptions are not available anymore: https://github.com/phausler/XcodeAPI/blob/gh-pages/Frameworks/DevToolsCore.md

You can use the class-dump utility to extract all Objective-C classes alongside with ivar and methods information.

Related

Access to a class only in framework

I'm creating a framework for iOS with this tool and I want to manage the visibility of my classes. Of course, I put my headers in corrects sections in my Build Phases > Copy Headers .
But when I add my framework in a new project, I still can access to classes (and their functions) stored in the Private section. I want my class "public" in my framework but "private" outside.
Is it possible ?
Thanks.
Tom
In the Objective-C runtime, everything is in the same global namespace. You can hide things by not including them in public headers, but they're still there and can be discovered and accessed using the lower level runtime APIs.

Header files without implementation

I'm working on a open source project, which consist on a framework for iOS devices, and one of the methods is not working as I expected. I tried to search for the implementation of the method, but all I found was a a header file and the method declaration; I didn't find the implementation anywhere. Neither did I find the .m file corresponding to that class.
So I have some questions:
How can a class exist without it's implementation and still its methods perform certain operations?
What is the purpose of writing this kind of classes.
In this kind of situations where should be the methods implemented?
Note
The open source project is FastPdfKit and the method is wholeTextForPage:
Well, those methods are somewhere, so it's not that they don't exist, you just can't see them.
Try for example to open UITableView.h, you can see the methods definition, but not the implementation. The implementation is hidden in the library, but you can't see it.
In a nutshell, developers do this to hide the details of the implementation of a class to other users. You just receive a header that tells you which methods you can use, and how, but the details about how are they implemented are hidden for you.
For example, Apple doesn't want you to see how they implemented UITableView, but they want you to know how you can use it.
Here you can find a tutorial about how to create a library for Objective-C:
Creating Static Libraries for Objective-C

API are only interface for referencing library classes or library classes themselves

I google this topic but I couldn't find the proper answer. I understand API as only Interface class that referencing library files to be used by other applications from other platforms. But someone told me that APIs are library files themselves.
I'm a novice to this topic so that suggest any answers to me, please.
In my opinion, an API is just a collection of interfaces. It is independent from implementation. Of course, usually, a standard implementation exists and is "associated" with the API but if the implementation is linked to the API, the API is not linked to the implementation.
If you take the example of Java, you'll notice that the API ( http://docs.oracle.com/javase/7/docs/api/ ) only show protected and public fields/constructors/methods/... It is not showing private stuff.
The API is reduced to what is visible for the user which is somehow the definition of an interface. The implementation is hidden.
What might be confusing is that the API is generated from the implementation but that doesn't mean that the API is the implementation.
I might be wrong but I think things are usually going like this:
An private API is defined (it is specification, so, it can be source code or any descriptive file)
An implementation is developed based on the private API
A public API is generated from this implementation and is published
The implementation is published as a Framework / Toolbox / or whatever the name
Developers use the public API to build their application and they choose the best implementation (which is generally the one from which it was generated).
Fell free to comment if you disagree ;)

C# style class extension in objective-c

I'm just learning objective-c after a fair amount of experience with C#. One of the things I sorely miss is the ability to write extension methods in a separate project that I could reference in all of my projects. Here's some naive c#:
public static bool IsShortString(this string s) {
return s.length <= 3;
}
In Visual Studio, I could just add a reference, an using, and bam myString.IsShortString() would be a, rather useless, method.
So I think I want to write a static library, but I'm not sure where I'm going from there.
One additional question, if I do write this static library, will I be able to use all of the methods throughout various files in the library using one #import directive, or will I have to import each header individually?
What you are looking for is called Category, and it allows you to add some additional methods to existing classes. Check the reference http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/chapters/occategories.html
You can create your own toolkit which is a static library containing categories you made. Common practice is to create one header file containing imports for all the headers in the lib, so when using it, you just do
#import "libName.h"
Also, when creating a static library containing categories it is important to include -all_load and -ObjC linker flags to your project.
The closest thing in objective-c is categories.
This is also a good tutorial on categories.

Using Objective-C Metadata to Generate Class Dependency Graph

This guy came up with a pretty neat tool to generate a class dependency graph - however, it relies on parsing your source code and looking for #import directives.
http://seriot.ch/blog.php?article=20110124
https://github.com/nst/objc_dep/blob/master/objc-dep.py
This is neat, but I have a number of problems with this. Not least of which is it doesn't take into account imports of imports nor prefix headers nor whether-or-not the class(es) in the file referenced by the import are actually being used.
I'd like to do something more akin to class-dump and examine the Objective-C metadata stored in the Mach-O file to generate an in-memory representation of the class dependencies.
I'd rather not do this from scratch, so I'm wondering:
Has it already been done?
Is there an open-source library which would provide me with the foundational tools I need to extract this information (a library which examines the Mach-O file and creates a façade of the Objective-C information contained within - such that I could iterate over all of the classes, their methods, properties, ivars, etc and scan for references to other classes) I figure class-dump's source would be a good place to start.
If you have experience in this sort of thing, is what I'm trying to accomplish feasible?
What roadblocks will I need to overcome?
Has it already been done?
Not that I know of.
Is there an open-source library which would provide me with the
foundational tools I need to extract this information?
At the core of class-dump is libMachObjC which does exatly what you want, i.e. parse all classes/methods/ivars and more. The API is very clean, it should be very easy to use.
If you have experience in this sort of thing, is what I'm trying to
accomplish feasible?
Unfortunately, no because some classes don't declare the real class but use id instead. For example, here is the information that can be extracted from a class-dump of UIKit:
#interface UITableView : UIScrollView <NSCoding>
{
int _style;
id <UITableViewDataSource> _dataSource;
id _rowData;
...
The _rowData ivar type information is id but if you check at runtime you will see that _rowData is an instance of the UITableViewRowData class. This information is not present in the Mach-O binary so you have no way to find the relation between UITableView and UITableViewRowData. The same applies for method parameters.
Here's a solution that relies on information in mach.o files, and generates graph dependency based on that information: https://github.com/PaulTaykalo/objc-dependency-visualizer
Has it already been done?
yes - but i can't recommend a good public implementation
Is there an open-source library which would provide me with the foundational tools I need to extract this information (a library which examines the Mach-O file and creates a façade of the Objective-C information contained within - such that I could iterate over all of the classes, their methods, properties, ivars, etc and scan for references to other classes) I figure class-dump's source would be a good place to start.
most use cases would benefit by using the objc runtime facilities objc/... rather than examining the binary.
If you have experience in this sort of thing, is what I'm trying to accomplish feasible?
yes. i've done something similar using the objc runtime.
What roadblocks will I need to overcome?
that depends largely on the level of detail you want... implementation time if you find no such implementation, but i figure you will find a few options if you google the more esoteric functions in the objc runtime; perhaps you would find one in an (open) language binding or bridge?
if you do end up writing one yourself, you can get registered objc classes using objc_getClassList, then access the properties/information you want from there.