How to add .json file to static library in iOS? - ios

My .json file contains some confidential settings and I want to include it in static library.But while supplying my static library I just want to provide .a file of static library to my client and I don't won't them to use drag and drop method in order to use its functionality.How can I achieve adding .json file in .a static file?

You cannot place any resource file inside .a file. Best option is to make a bundle file and keep the json file inside it. But then the your client can see those file if he wants to.
If confidentiality is a matter, another option is to create a class that returns this json as NSString.
For example :
#interface LibraryHelper
+ (NSString *)jsonConfig;
#end
#implemenatation LibraryHelper
+ (NSString *)jsonConfig {
NSString *json = #"<your json string hard coded>";
}
#end

If you don't want to have the developer drag another file in along with the .a binary then you need to compile the json file into the binary itself - as a string then parsed at runtime.
Having said this, if you just need a few config params then you'd be better off just putting the values directly into variables.
Also check out iOS .framework bundles in Xcode 6, they provide a nice way to group your binary, header files and any additional resource files. In the Xcode 6 new project window choose Frameworks & Library > Cocoa Touch Framework.

Related

How to list all files for one target in Xcode

Is there a XC command I can use to list all files for one target?
Unfortunately, I'm unaware of any environment variables available to a build script.
The best way that I know of would be to open the pbxproj file inside your xcodeproj bundle and parse it. Luckily, it seems to be in a plain text format compatible with plists. You could invoke the plutil command to convert it to XML or json for another tool/command to consume if that is your goal. You can utilize a "Run Script" build phase if you need this list as part of your build. You can also instantiate an NSDictionary directly with that file if that is useful to you.
The plist is pretty simple. It consists of a root dictionary with some version strings and a giant objects dictionary. Each object has an isa type and the one you are interested in is the PBXNativeTarget type. Scan until you find the target with the correct value for the name key. Once you find your target look at its buildPhases; AFICT the first entry in buildPhases is the key for the corresponding PBXSourcesBuildPhase object. That build phase object has a files array which contains yet another set of IDs (one for each file compiled into the target) which point to a PBXBuildFile object, which has a fileRef string as a key to another object, this time to a PBXFileReference. This object finally has a path key which will be the path to the source file.
Wait... did I say "simple"?

How to use swift files in objective c

I want to use my Swift files in Objective-C code. I found different link that say how to do it.
My project name is: Test-Project.
I imported #import "Test-Project-Swift.h" to my .m file to use needed classed in objective c source code.
I watched this video and there is no problem, but I have 'Test-Project-Swift.h' file not found.
As we recognized:
It looks like the problem with "-" we need to change it to "_" - "Test_Project-Swift.h". I've checked Objective-C Generated Interface Header Name in the project settings.

Adding file to specific folder in iOS application

We are making a common library in c++ for database and file reading.
We have decided a common folder structure for placing the files.
For eg. Insert statement files will be in a Lib/Files/Insert/
I will pass root directory of the project to c++ library, the library then will automatically append the path of the file to root directory.
For eg. If I need insert file of Author, I will pass /path/to/root/ to library. The library will append the rest of the path and pick up file like this: /path/to/root/Lib/Files/Insert/Author.txt
I was not able to open the file from c++ code.
Then I tried this to get the path of file using Objective-C:
NSString * authorPath = [[NSBundle mainBundle] pathForResource:#"Author" ofType:#"txt"];
It is showing the following path:
/Users/homam/Library/Application Support/iPhone Simulator/7.0.3/Applications/9C882381-DAA7-464D-AA84-8DB9288AAD71/CoreLibraryDemo.app/Author.txt
Although I have placed it in the folder /Lib/Files/Insert/, it is not included in the above path before Author.txt
So how can I maintain folder structure in iOS and read file from c++ library.

Which zipping library should I use to properly assemble a valid XLSX file in Objective-C?

I am trying to modify an XLSX file programmatically using Objective-C.
So far, I am only modifying the data on one of the sheets. The steps I am taking are as follows:
Copy the XLSX file to Documents folder
Unzip the XLSX container with keeping the directory structure
Parse the corresponding sheet XML file (sheet2.xml in my case)
Add some rows
Rewrite the XML structure and save it
Put the updated XML file back into the XLSX container
However, the new XLSX file becomes corrupt. I am using GDataXML for XML parsing/writing and Objective-Zip for zipping/unzipping.
I know that the XML file I have created is proper, because when I manually unzip and the re-zip the corrupt XLSX file, it opens without any errors. I have done this on both OS X (using Unarchiver) and Windows (using 7-Zip).
The problem is either with the Objective-Zip library, or the way I use it. Below is how I implement the zipping method:
ZipFile *zipFile = [[ZipFile alloc] initWithFileName:XLSXDocumentsFilePath mode:ZipFileModeAppend];
ZipWriteStream *stream= [zipFile writeFileInZipWithName:XLSX_WORKSHEET_XML_SUBPATH compressionLevel:ZipCompressionLevelNone];
[stream writeData:data];
[stream finishedWriting];
[zipFile close];
I also tried the other compressionLevel arguments available with no luck:
ZipCompressionLevelDefault
ZipCompressionLevelBest
ZipCompressionLevelFastest
My questions are:
Which zipping library should I use to create a valid XLSX file programmatically?
If Objective-Zip is suitable, what is wrong with my code?
From an answer to another question, I found out that: "The OOXML format imposes that the only compression method permitted in the package is DEFLATE".
Is it possible to force Objective-Zip to use DEFLATE? Or is there an open-source iOS zipping library that uses DEFLATE?
I found the answer upon doing some research and also having a one to one correspondence with Objective-Zip's developer, flyingdolphinstudio.
First of all, Objective-Zip uses DEFLATE as the default compression method. I also confirmed this with the developer, who told me that using ZipCompressionLevelDefault, ZipCompressionLevelFastest or ZipCompressionLevelBest for the argument compressionLevel: will guarantee a DEFLATE compression.
So, the problem is coming from the mode: argument, which is ZipFileModeAppend in my case. It seems that MiniZip does not have a method to delete the files inside a zip file and that's why I am not overwriting the existing file, but adding a new one. To make it more clear, take a look at how my xl/worksheets folder look like after zipping it using Objective-Zip:
So, the only way to create a valid XLSX container is to create the zip file from scratch, by adding all the files and also keeping the directory/file structure intact.
I hope this experience would help somebody out.

How can I include some js file in JSFL file?

I'm using JSFL to writing some script, I need parse json string from some config files, so I need the JSFL can parse json string, but JSFL seems can't do this. then I thinks to include some json lib, like json.js, to JSFL file.
Way can I include the json.js file to my JSFL file?
Sorry for my english.
The absolute bare minimum would be:
// #include Config._jsfl
var scriptPath = FLfile.uriToPlatformPath(fl.scriptURI);
var scriptPathEnd = scriptPath.lastIndexOf("\\");
scriptPath = scriptPath.slice(0, scriptPathEnd + 1);
fl.runScript(FLfile.platformPathToURI(scriptPath + "Config._jsfl")); /*jsl:import Config._jsfl*/
This is more or less copied from my code, JSL tags included. I make the extensions on any libraries to be ._jsfl so that if it's in Flash's Commands folder, they don't show up in the menu.
I wrote a set of static classes (a Logging system, URI conversions, array utility functions) and wrote a global include function using them to automatically convert a relative path to an absolute URI based upon the running scripts location so that I could just say include("file._jsfl"); to simplify my scripts. HOWEVER all my scripts have to do that first include as shown above to gain the include function. Since my include function relies on a handful of static classes, I've not pasted it here.
Edit: spelling error.
If the library is local, you can store it in a subfolder of your Flash config path, i.e.
C:\Users\username\AppData\Local\Adobe\Flash CS6\language\Configuration\jslibs
Then, it is quite easy to include it in a single line:
fl.runScript(fl.configURI + "jslibs/file.js");

Resources