I have a swift iPhone application that stored data the user entered into various variables, structs, objects, etc. I would like to write that data to a file. I have a template that will be stored in my project files on the phone. So what the app is supposed to do is take that template, save it as another file, and add the data the user entered from the app to the file.
My question is, I already have it set up so the user enters the data into the app using swift. Is it possible to integrate C so that the C file takes the information from Swift file and writes that data to a file? If so, can you point me to a direction? (tutorial if possible..)
I did some research on it and sadly the only thing I could find is obj-c stuff with view controllers and how to integrate obj-c with swift.
Thank you!
Yes! You can mix them. This is a link to download e-book "Using Swift with Cocoa and Objective-C"
It's FREE.
https://itunes.apple.com/it/book/using-swift-cocoa-objective/id888894773?mt=11
Related
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.
I'm trying to build a simple to-do list app with Swift 3 and Xcode 8. It includes a text input box, a submit button, and a table, where each cell includes a title and a subtitle that shows the date. So far, all of this has worked.
Currently, I'm trying to get it to save when I leave the app. I've tried user defaults (which I have succesfully used in the past, but wasn't working for this), core data (which seemed like a lot of excess code, will do if I have to), and a JSON file I tried to read and write from with SwiftyJSON (have also succesfully used this). None of these have worked.
What would be the simplest/best way to solve my problem?
Thank you!
The simplest way to persist data locally in those circumstances is probably to use NSCoding. See the "Persist Data" section in Apple's Start Developing iOS Apps (Swift) guide.
You might also want to take a look at Apple's sample code Lister (for watchOS, iOS, and OS X), which demonstrates a productivity app for iOS and OS X that enables you to create and share to-do lists across devices. A user can store their documents both locally or in iCloud, but this may be more than you need for your use case.
You can save your data into: userdefaults, files in documents folder, coredata, SQLite db, third-party like realm. You can send also to your remote server.
I installed Realm manually, and it is working on my main app. But on the today extension, i can't even import RealmSwift. I apologise if this question is a newbie question, but I've been searching the web and I can't find a proper updated version. I have read https://realm.io/news/tutorial-sharing-data-between-watchkit-and-your-app/ but it's written a year ago and it does not work anymore.
So how do I go about using realm to share data between the main app and the extension?
Thanks for the help!
Even though that article is quite old (It's not even using Realm Swift! It's using the Objective-C version bridged to Swift!), the principles of using Realm with iOS 8 extensions haven't changed to the point where the information in there has become outdated.
The main points to consider:
For all intents and purposes, a Today Extension is a wholly separate app from your main app. It needs to be able to be fully self-contained in its operation.
As long as you're using the dynamic framework version, you can link one copy of RealmSwift.framework to both your main app, and the extension.
You need to make sure you've set your Realm file to be saved in the containerURLForSecurityApplicationGroupIdentifier URL. This is the only place where your main app and the extension can share files.
Because the Today extension is technically a separate app, make sure any Object subclasses you've made are included in both your main app, and your extension's 'Compile Sources' build phases.
Please let me know if you need any more clarification. :)
I am trying to build an iOS swift framework to display encrypted photos. Photos are sent by my server (something like a hashed binary file) after calling a specific API with specific details. I will then decrypt the photo, and display it to the user.
Correct and point me in the right direction if I am wrong, but swift only allows frameworks - meaning no static library. And this will expose my implementation details (such as the method to decrypt my photo).
What I would like to achieve is to create a cocoapod distributable framework for paid developers to implement (once they subscribe to me). It is supposed to expose simple public APIs, and hide implementation details.
I have tried various ways to achieve that but to no avail. I would really like to keep the implementation to swift codes only, with minimal Obj-C codes.
Build a swift framework, and build an objective-c static library as a wrapper
But I cannot seem to get it to work. Any idea if this is possible?
Build a swift framework in a swift framework
Stupid idea, i'm able to see the framework's implementation details within the other framework...
Build a swift framework, and build an objective-c framework as a wrapper
I cannot seem to get this to work either...
I have been working on this project for about 2 weeks now, and have been all over Googling for it. Just in case anybody would like to try, you may try to do the following and check if it works.
Cocoapods Friendly Framework
Implementation Details Hidden
Uses Alamofire (or any public framework that connects to internet)
Any help would be appreciated, thanks!
Actually, I am working on one app and started with the objective-c. Now i have started working on swift with the same app for the further development and it will work with both the class (objc and swift).
Now I have doubt that it will accept by apple store or not.
Please help me.
This is fine, Apple provides the mechanisms for interacting with both and will not drop support for Objective-C for quite sometime. Many large organisations still have the majority of their code written in Obj-C (including Apple) so they need to give people time to transition, they aren't going to switch over immediately to a relatively immature language.
You can use Swift and Objective-c together. There is no issue in it. You need to create a bridging header file.
Please read this
Swift and Objective-C in the Same Project