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

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.

Related

Xcode: use a static library in a framework?

I have a framework that links against two static libraries. Each static library is a target and the framework is a target. The framework wraps the static libraries and clients of the framework only care about calling framework code (which in turn may call code from each static library). Is is possible to have the framework include the required headers and object files? When I build I get the infamous Include of non-module header inside framework module error. Each static library exports its headers and I've added the headers as public headers in the framework. Still no luck (and I would think there's a solution that doesn't require this).
Each static library must export a module.modulemap file with its headers. Contrary to popular wisdom, once this is complete, you need not add a bunch of headers to the Public section of the framework's Headers build phase in order to alleviate the error. The process is described in detail here: https://bjhomer.com/2015/05/03/defining-modules-for-static-libraries/

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 do I access a public header from a static library that imports a private header? Recieveing Lexical or Preprocessor Issue

I have a static library project in Xcode where I have utilized the Copy Headers portion of build phases to make only certain classes accessible from another project and keep all other classes from being accessed outside of my static library project.
I have created a View Controller project where I link to the library (.a file) that I have built. When I import in my header that exists in the include folder auto generated by Xcode's Copy Headers feature (I'm assuming this is now a public header file), let's call it Header A, it returns an error Lexical or Preprocessor Issue, and that it cannot find a header file which is imported by Header A but was not added to the Copy Headers section because I do not want users to have access to it (I am assuming it is a private header since I have not added it to the include folder through Copy Headers), let's call it Header B.
If I copy the header file to the include path, than Xcode allows navigation to see the code which is what I am trying to avoid. Is there a way to only allow access to certain classes, which may themselves access private classes? Is there a certain way to declare classes as Public and Private that I am missing?
I appreciate your help!

public header files in iOS static library

I have developed static library for my applications. It generates .framework, .bundle, .a files.
I want to enhance the use of library. Currently my framework has 4-5 files as public scope to application. Only those headers are visible to application (Interface). Is there any way to create common header file at build time of framework, which will contain/ imports of all public files from my source code(frame work code.)
e.g. once I build framework code, it will generate .framework which will create/have common.h header file consisting all imports of public files.
By doing this, application needs to import only common.h. I know we can do this manually also. But is there any scope to do this by script at build time?
Thanks.
I tried using script I got success!
Here are the steps:
1. In build script where we create fat binary, we need to find out all .h headers. We need to take path in variable.
2. Loop and collect all public variable
3. Create and locate common.h (This will be path of header folder in .framework)
4. Put all files common.h

How to create static library from an existing framework in iOS?

I have been provided with a framework by a third party vendor for an iPhone hardware accessory. So I have a folder like Device.framework. Inside that folder is a binary file and a set of .h files. There are instructions for how to add this to an iOS project and use the classes contained within. However, I'm actually using MonoTouch and want to use a static library.
Is there a way to create a static library that makes all the classes from the framework available in the static library? So in my MonoTouch project I would link in the static library and have access to that framework.
A *.framework is simply a package containing: the static library, headers, associated meta data. Copy and paste the .framework and extract the static *.a file and related header files.
Then it's simply a matter of using the MonoTouch btouch tool to bind the static library for use in your MonoTouch project. There is a great example of how to bind a native library to MonoTouch on Github. With guidance on targeting simulator + device and using the LinkWith attribute to embed the static library in a single *.dll:
https://github.com/xamarin/monotouch-samples/tree/master/BindingSample
Also, make sure to check out the btouch Reference documentation here:
http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types
Rename that binary file to Device.a. You can do that as the framework you mention is not done by Apple, hence it has to be a static library and not a dynamic one.
Make sure your project links that library (Device.a).
Include the headers in your project and reference them where appropriate.

Resources