简体   繁体   English

如何在iOS的静态库中添加.json文件?

[英]How to add .json file to static library in iOS?

我的.json文件包含一些机密设置,我想将其包含在静态库中。但是在提供我的静态库时,我只想向客户端提供静态库的.a文件,我不会让他们使用拖动为了使用其功能而使用drop方法。如何在.a静态文件中添加.json文件?

You cannot place any resource file inside .a file. 您不能在.a文件中放置任何资源文件。 Best option is to make a bundle file and keep the json file inside it. 最好的选择是制作一个捆绑文件,并将json文件保留在其中。 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. 如果需要保密,那么另一个选择是创建一个类,将该类作为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. 如果您不想让开发人员将另一个文件与.a二进制文件一起拖入,则需要将json文件编译为二进制文件本身-作为字符串,然后在运行时进行解析。

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. 还请查看Xcode 6中的iOS .framework捆绑包,它们提供了一种很好的方式来对二进制文件,头文件和任何其他资源文件进行分组。 In the Xcode 6 new project window choose Frameworks & Library > Cocoa Touch Framework. 在Xcode 6新项目窗口中,选择Frameworks&Library> Cocoa Touch Framework。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM