I'm currently working on a medical research app with swift based on ResearchKit, which is an objective-c based framework. I'm trying to create a conditional ORKOrderedTask, like the one at: https://gist.github.com/mattio/9126ecc4f08b9f0497d9
Basically, it says that if the answer to the previous question is yes, then display the next question, if not, skip it. I can find the code for it in objective-c but I'm having trouble converting it to swift.
The recently merged ORKNavigableOrderedTask provides that exact functionality by means of using NSPredicates to check against previous or ongoing task results.
In the RKNavigableTaskExample repository you can find a small self-contained example on how to use the class. The example is written in Objective-C, but it should be easy to call the same APIs from Swift.
Related
I'm looking to make an app which allows you to use Swift code within the app - similar to other Swift-based learning education apps to help you learn the language.
Is there a way to use the open source Swift code, for example, in any way to understand the syntax and possibly run the code for typed-in Swift code?
An example of an app I found on the App Store which can do this is called Sedona.
From GitHub apple/swift/.../Syntax there looks to be Swift syntax APIs, presumably for use by IDEs.
Am I looking in the wrong place?
Do these types of apps make their own Swift translator?
Is there some other way this is done?
Efficiency & optimization is not a priority, however would be a benefit.
It in no way needs to include very complex Swift.
Note: This is for an iOS app only, so Terminal commands would not work.
We know iOS life-Cycle as below Graph with Objective-C:
e.g. where is main() in Swift project , or where is AppDelegate.swift's functions?
It's the same because it's not a language depending life-cycle. It's an Application life-cycle.
You could change the language, but the way application works still be the same. If there were any differences, you won't be able to use swift/objc in the same project.
All calls are still there, but they change the way they look (but not named) a bit because of swift syntax. You could look them up here: Looking to understand the iOS UIViewController lifecycle
As an experienced Objective-C developer who is now learning Swift , I'm really missing some of the reflection and dynamic features of Objective-C.
For eg: I had written a JSON serializer which automatically mapped keys and values using KVO and Objective C introspection , and there are open source libraries like Mantle which do this.
I could declare my object as an NSObject subclass and proceed but I feel that this is not the Swift way of doing things.
Is there any other way to accomplish the same tasks , while avoiding boilerplate , using what Swift provides ?
EDIT: (2016) this answer is auto-dated. Some of the advice may still be relevant but now that Swift is open-source, I would look into other possible answers.
There is no native KVO reflection like what you described built into Swift. See:
https://stackoverflow.com/a/24092370/798682
And based on what we do know about how the Swift compiler optimizes method execution at compile time (vs the pure runtime implementation of ObjC) it doesn’t seem likely to be added anytime soon. See https://stackoverflow.com/a/25438299/798682 and
http://blog.untitledkingdom.co.uk/obj-c-vs-swift/
for more info on that.
With all that being said, here is a blog post on some KVO alternatives in Swift:
http://blog.scottlogic.com/2015/02/11/swift-kvo-alternatives.html
and another that details some of the reflection capabilities that are in Swift:
http://freecake.angelodipaolo.org/simple-reflection-in-swift/.
I want to use apple maps in Swift to be able to put in, lets say, 3 addresses. And then the program will sort out the quickest route. My problem is that i can't even find the apple files that show using maps in swift.
I looked here
The Swift Programming Language - Basics
(not just the intro, most of it).
And in the intro it says
Location services are provided by the Core Location framework, which defines Objective-C interfaces..."
I can't find example code for using the maps for at all what I'm looking for so i guess what I'm asking is:
Will this work in swift?
Do you know of any files that may help or websites with example code of how to accomplish this?
What's the problem here? E.g. the documentation for CLLocation -startUpdatingLocation includes a description of its Swift binding as well:
func startUpdatingLocation()
You may be looking at a situation where Apple just did not update a Programming Guide since Swift has become available and you may typically infer "Objective-C and Swift" where it mentions "Objective-C".
I need to present and open pdf documents in my app. I would like to avoid third part libraries, because of update reasons (and I couldn´t find anyone created in swift).
I have been looking at QLPreviewController, UIDocumentInteractionController and presenting the pdf in an UIWebView. All these alternatives works fine for just presenting the pdf but I can´t find any built in search. I want functionality like the iBooks app.
Any advice is appreciated!
You'll likely wont find any 3rd-party frameworks written in Swift yet, simply because as of Swift 2.2 it's not binary compatible yet, and any binary framework written in Swift would be very fragile to break with even a minor update of Xcode (and updates to the compiler, that is).
I'm working on the commercial available PSPDFKit SDK for both iOS and Android. We're actually using a lot of C++ internally since raw performance is very important and Objective-C (and for many things, also Swift) are not yet fast enough for certain tasks.
We did invest a lot of time in adopting the latest Objective-C features such as nullability and generics next to declarations such as noescape for block-based API to make our SDK great to consume from within Swift.
While a separate Swift-wrapper could offer additional convenience, you'll find it very simple to use, and we're always working to adopt more features that improve bridging as they come available - there are a few interesting things in the Swift 3 proposals.
If you do not want to go the framework route, you can use CGPDFScanner to base a custom text extraction engine on. You will need to read up on Character Map Parsing - Page 446ff and many other sections - extracting text from a PDF document is surprisingly difficult, and after much work you'll be left with individual glyph positions and need to approximate where words are and if the document uses spaces or if you need to synthesize your own to correctly extract text. It's something that just takes a lot of experimentation and approximation to get right.