Exposing methods in iOS static library - ios

I want to expose only selected methods inside my Static library to classes outside.
Is there a way to do it?

This is impossible the way Objective-C works. The best you can do is not publishing those methods by declaring them in an internal header (either in a class continuation or a category) which you don't give to the user of the library. Using tools like classdump or the runtime APIs those methods still can be found and called.

Here's on approach to do this:
Take the methods you want to be private and put them in a separate category. E.g. MyClass+PrivateMethods
Make sure these MyClass+PrivateMethods.h files are not included in the Public part of the copy headers build phase, so they can't be seen by those who use the static library. (Make sure you understand the three different options for Copy Headers - Public, Private, and Project).
#include these MyClass+PrivateMethods.h files where you need them within implementation files (.m) of your static library.
Profit.

Related

How to prevent exposure of methods and header files(.h) of other library

I’m creating one framework, which is using another third party static framework (has .h file, which contains public methods) and I don’t want to expose the header files(.h), code, methods and classes of that library to the user of my library.
Any ideas will be very appreciated. Thanks.
Easy to control header file visibility in Build Phases

iOS: Can i create a static library with all classes (.h & .m) as public?

I have a bunch of classes that i want to share with others so i thought of creating a static library but i don't want to hide my code. I want to allow them to put change in the library if they want to.
I can share a folder of files but i want to merge all the files into a single package so it's easy to manage and maintain.
Static library generally shows only header (.h) files to users but is it possible to make implementation (.m) files also visible?
I've one more static library which is a dependency for this one. Can i put one static library inside another? or i have to add both files in my project?
I didn't do this library stuff before so am i going in a right direction? or is there any more appropriate way in iOS that can fulfil my requirement?
Thanks!
Ship the code as a framework and instead of sharing a folder, turn the library into a regular project on GitHub or anywhere else. Add what’s needed to install the library through CocoaPods or Carthage. Make proper releases with semantic versioning, write a proper Changelog.
It’s a lot of stuff to go through for the first time, but it’s a good practice that will pay off. See my simple goo.gl client for an example of such library.

xcode static library public/private/project header files

So, I have an iOS app project with a static library as subproject. As found multiple times here on SO, you should set the visibility of the library header files to public/private/project, depending on who should be able to use them.
Based on that, I created one class with a header file that exposes functionality to the app project (or whoever is going to use this library). Naturally, this header file imports a number of headers from other classes inside the library project. As these other header files do not provide functionality that should be exposed to the library's users, i would like to set these to "project", making them invisible to the rest of the world.
However, when i set header files to "project" they don't get copied into any of the private or public header folders. This results in a 'ProjectHeader.h' file not found error when using #import "ProjectHeader.h" in the PublicLibraryClassHeader.h when compiling the app project that uses the library.
So the question is: How can I set header files to "project" in a library project and stil use them from within that library project? Am I misunderstanding the concept of public/private/project header files in static libraries?
The easies way is to convert your static library into framework. Framework is a static library in a specific container, that does all magic for you. Btw, this words about public headers are related to frameworks, not to static libraries.

How to access variables from iOS static library in client application?

I am builiding libraries in iOS, for that i want to access variables from my iOS static library. To do this, is it necessary to declare variables used in my library class as public variables?, so that I can access variables from my library class from another application?
If so, how to declare variables as public in library class? If not, is there any other method to access variables from library in client application?
If the headers are copied in the Copy Files build phase, then their symbols will be available to the client application which links your static library. This build phase is created automatically for you when Xcode creates the static iOS library project.
If you wish to exercise more control over which headers are public and which are private, then you'll need to create separate copy headers build phases for public and private headers and manually move header files between those build phases. You'll also need to adjust the header search paths. This blog post may help with those implementation details.

Create ios static library with with more classes

I want to develop iOS static library and distribute to other developers.
I have started some R&D and found only one way to create static library with only one class which is having header file and implementation file.
I would like to create static library with more individual classes. Now we are creating static libraries with only header files and implementation files.
Is it possible to add XIB files also to that? Can anyone guide me to solve this requirement?
As you are saying, you have created static library, then you just need to add more files. Suppose you can want to make some file to make public to developers then you need to make it public scope.
This may help you... http://www.blog.montgomerie.net/easy-xcode-static-library-subprojects-and-submodules

Resources