Embed Core Data into a Static Library - ios

I am trying to embed a core data model into a static library or a framework. I have stumbled upon a few tutorials and SO questions like this one. The process is to create a bundle target where you can embed the core data model file.
This is working fine, but it doesn't seem good enough for me. I have noticed that Google Analytics have implemented a static library that uses core data and all you have to add is headers and the .a file.
So my question is, how can we embed core data in a static library without having a bundle, just like Google Analytics?

You can create the model in code by instantiating instances of NSEntityDescription, NSPropertyDescription etc. This involves a lot of boiler plate code but it is relatively straight forward.
An alternative, which I can't recommend but will mention, is to include the ManageObjectModel in the binary in some form. It can then be extract to a temporary folder and read as per normal. (Embedding Resource Files in a Cocoa Foundation Command Line Tool)

Related

Importing a .bundle for iOS with executable code

I am trying to make an application in Objective C where a user can download a .mlmodel file from Google Drive and then dynamically load this model as a class and run its methods that come from CoreML's MLModel interface.
Looking at Apple's documentation, it appears I should be able to do this using bundles: "You can make your application extensible by designing a plug-in architecture. This way, you or third-party developers can easily add new features without recompiling the whole application or even having access to its source code."
My existing code downloads their .mlmodel file from Google Drive and saves it to the Documents folder. However, not finding a way to instantiate this as a class, I switched approaches, and will instead download a .bundle file from their Google Drive and then try to make the class from the files within it. I am struggling to find any examples of how to do this. First, I do not know how to get a .bundle file after making an App, setting the principal class, and setting the BundleID as described here. Second, I am concerned that although the documentation seems to indicate that what I want to achieve is possible, I have run across several SO posts that say that running any sort of uncompiled code, dynamically linked code is impossible on iOS. I would appreciate any clarity on the matter.

Data Serialisation in Objective-C (Avro alternative)

I've been the last week trying to serialise all of the classes of one iOS project (Objective-C).
Due to I use to do it in Android projects with Avro (Apache) library, I've been trying to do the same in the iOS project, however, the first thing that I noticed is that there is not too much information about Avro in iOS.
First thing I tried:
Implement the library ObjectiveAvro using CocoaPods but some classes in the library Avro C were not found when imported.
Second thing I tried:
Remove and do again the previous process but this time only with the Avro C library but the same error appeared.
Third thing I tried:
Implement BlueSteel framework using Carthage. This is a swift library but I wanted to try if I could use it somehow in an Objective-C project. I couldn't.
I just need to serialise and deserialise data providing a schema as you can do with Avro (Android) in an Objective-C project and the last thing that I want to do is convert the whole project to Swift.
So do you know what's the current way to do that in Objective-C?
I could figure it out how to do the Third thing I tried:
Basically, it's necessary to import the library through Carthage, then create a new Swift class which is the one that is going to "talk" with the Swift library, due to we are in an Objective-C project. XCode will ask you to add a "header-class" and press "yes".
Then it's as simple as using the Swift to call the library methods and call the Swift class from the current classes. Swift class in Objective-C project
Finally just to inform that the BlueSteel framework is a nightmare due to is really limited and really poor documented therefore I still don't know a real alternative.
However, if you're going to use it, have in mind that the classes are not autogenerated so you need to do manually the conversion to Avro and sign results.

Different user interfaces for a core functionality

I have a Swift project which contains a lot of screens (got from xibs and storyboard) with many core functionalities.
Now two different projects based on these core functionalities are needed. The requirements are these projects must have different headers, cells, colors, assets, etc.
Which strategy would you follow to get different interfaces based on target/project, from a single core framework?
static config:
maybe pull all project related variable, and put it in a plist file, working like archiving and unarchiving. when framework loaded, get boot info from that file.
or abstract all these info into a static class? works almost the same way.
some way dynamic config:
delegate pattern: every project who want to use your framework, must
implement one object with pre-designed protocol, use the object to bootstrap framework, your framework should get the project layer based question answers like header file, assets, etc.
sorry for my English, hope this helps.
;)

Adding Realm objc files inside own static framework

I am creating framework in ObjC first time.
I want to store data inside realm dynamically. i.e. I have JSON for schema and data, and want to create classes, it's properties, objects, etc dynamically.
I have gone through their example code, they have provided DynamicTests.m where they have created data dynamically but I don't get it correctly.
Now I have few concerns and doubts.
What files/Folders should I include to create realm database at runtime? (ie. script folder, configuration Folder, swift folder, core folder?).
How to create dynamic schema and classes with their properties?
Is there any limitation or precaution that I should keep in my mind?
Good questions!
What files/Folders should I include to create realm database at runtime? (ie. script folder, configuration Folder, swift folder, core folder?).
Realm is no different than any other framework in this regard. When building a static framework that depends on another static framework, statically link the dependent framework all you'll be all set. No additional files are required.
How to create dynamic schema and classes with their properties?
By importing the Realm.Dynamic module, you can construct RLMProperty , RLMObjectSchema and finally RLMSchema instances which you can then pass in to RLMRealmConfiguration.customSchema. Also make sure to set the RLMRealmConfiguration.dynamic property to YES.
Is there any limitation or precaution that I should keep in my mind?
The dynamic APIs are a bit verbose and not included in the HTML API documentation, so you're using Realm in "expert" mode ;). That being said, the Realm team is happy to help with any issues you might encounter (I work at Realm).

Create Framework / Library / Module of Swift Objects in Xcode

I am a (very) novice iOS/Swift programmer with a basic question about moving reusable software objects to their own ... something.
I am developing three iPhone apps that present information from three distinct data sets. Those data sets contain unique information but are structurally similar. As such, the apps share some Swift classes that are identical, specifically the classes that model the data. As I continually refactor the code, I find that when I tweak a class in one app's project, I have to remember to go to the other two projects and make the same tweaks to the same classes for those apps. It's getting to be a big headache.
What I would like to do is have one class definition in its own ... something that I can share, link, import, or attach to/from each app's project. From my online research, I suspect that the ... something is a library? or maybe it's a framework? or a module? I have found all three terms are used, but I am not sure how they relate to each other.
Given that all of the software I am writing is in Swift, does Xcode support what I am trying to do? Thank you!
It seems you have the issue of needing the same Swift class in multiple projects. You could build a Framework (aka Module) for this class then copy it in to each project. This is probably the formally correct approach but it is a bit of overkill for just a single class.
Instead, you could just make the file in the Navigator panel a reference in each project to the one actual file.
You could also make a Workspace and then put each project into the workspace and just have the file at the top level (but this may introduce some build complexity).

Resources