String parser for Swift? - parsing

I'm working on a project that draws functions on a plane (Similar to Apple's Grapher utility).
I'have already compiled this app few months ago in Obj-C, and was running clean and fast.
With Swift, I changed a bit the scheme of the app, but I'm still using CGMathParser, a great collection of classes to manipulate and evaluate strings like y=sin(x) or y=log(tan(x))
However the app is now slow and laggy, and I'm thinking that the reason hides in the fact that I'm mixing Swift with Obj-C.
Do you know if there is any kind of parser already optimized for Swift that will be fast enough?

The Swift compiler enforces bounds checks and various other 'safety' features. If you compile with the -Ofast option these checks are removed, which typically makes your app run a lot faster.

Related

Codename One (or ParparVM) how to compile Java library into iOS library

By checking the Codename One website and ParparVM Github, its guide only show how to build the Java (with Java Main function entry point) into the native executable/app (iOS), but I can't find any guide to build/compile Java into iOS share library (either in C source or binary, as long as can be reused by swift/objective-C from iOS app).
So are we able to do so? is there any guide for that?
It wasn't designed for that purpose so it probably won't work well for it. There are some inherent design decisions that would make it very difficult to get ParparVM to work with a library. Two big ones:
The GC needs to work with roots and would have a hard time collecting without full control of the app
The code generated looks "awful". Method names translate to very long function names in C with a very convoluted syntax to allow all sort of VM edge cases such as covariance
I suggest you look at J2ObjC. I haven't checked it out in ages but it was designed exactly with this use case in mind. It doesn't have a "real" GC but that might be OK with ARC. It works with your sources and produces libraries that look a bit more "natural" on iOS.

Recognizing Swift syntax from within coding educational app

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.

iOS app that has both Objective-c and Swift - pros & cons

I work with an App that's 100% Objective-C and I'd like to start transitioning over to include Swift. Due to the size of the codebase, it's unrealistic that I'll have a 100% Swift app anytime soon.
As soon as a swift file is added, I noticed that the app size increases because now, the app needs to the include Swift run-time.
How else does things change? As soon as you include a Swift file, what is the process that the compiler and linker undergoes to ship a binary that is now multiple language & related frameworks?
Are there any other caveats in transitioning into a mixed language world in a somewhat large codebase?
In my experience, it works surprisingly well. It is advisable however, to wait to Xcode 7 / Swift 2.0 / Objective-C with generics support as that will eliminate a round of updates, allow you to interop from Objective-C with more elegant Swift code, and eliminate the Swift RT linking concern now that they have stabilized the runtime.
Aside from that, both compilers need to run, Swift first, Objective-C second, the swiftc compiler can be pretty fast or really really slow, depending on what innocent and otherwise legal Swift code that you write (this is also true of a Swift-only app of course).
Getting started, you need to read the interop guide, learn how the bridging header works, and are then mostly on your way. I would say that having a mixed app is actually a blessing as you are not pressed to learn and do everything at once. Opinions will vary of course, but this is mine.

Sprite Kit and IOS Development

Just a few questions which I can't find answers to anywhere:
To code games for IOS using Sprite Kit, do you also need to know Objective-C or Swift?
Can you code high quality games without knowing Objective-C or Swift?
Thanks!
SpriteKit is an Apple framework developed for Objective-C / Swift application. So, yes you'll need at least some code basics notions.
"Yes". You might be able to develop game with Unity2D for example, but that would include using another language to write your scripts.
I'll try to expand a little bit previous answer.
SpriteKit is an Apple framework developed for 2D/3D games. It uses Swift or Objective-C. Advantage of using this is that you can be 100% sure that this game will work flawlessly on iOS devices. Disadvantage is that you are locked only to iOS devices. If you have 0 knowledge of Swift or Objective-C, and you wish only to develop for iOS, I would choose Objective-C. It seems a little harder to learn and understand, but compared to Swift to it seems that Objective-C is still (and will be for long time) superior to Swift. Although, it just be my personal preference, because I truly hate Swift. (You can achieve same things in both languages) :)
I started this way, I do not regret.
You can develop games and apps for iOS without knowledge of Objective-C or Swift. You can use programs like Unity, Unreal engine, Corona, Cocos2D/3D. However these programs require learning another language to write your game (c++ or something else). You can also use GameSalad for 2D games. It requires 0 coding, many things are drag and drop, but you do need to understand logic behind it. For example, it wouldn't be programming but it would be coding :)
GameSalad is easy to learn, fun as well, but forget that you will be able to create any serious game logic or more advanced game than 2D platform one. I tried it, but very soon changed to Objective C and XCode.
If you decide to go with learning actual language (which I would strongly suggest), I would recommend either Objective-C or to learn Ionic software. Ionic uses javascript, but when you learn how to make games/apps you can easily distribute it to ANY platform: iOS, Windows mobile, Android...XCode is better software, but learning Ionic has huge advantage, and that is single click to deploy app on any platform.
Good luck.

iOS PDF native search

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.

Resources