Skip to main content


Showing posts from January, 2016

netfox - A lightweight, one line setup, iOS network debugging library!

A lightweight, one line setup, network debugging library that provides a quick look on all executed network requests performed by your app. It grabs all requests - of course yours, requests from 3rd party libraries (such as AFNetworking, Alamofire or else), UIWebViews, and more
Very useful and handy for network related issues and bugs
Implemented in Swift 2.1 - bridged also for Objective-C
To start netfox add the following line in didFinishLaunchingWithOptions: method of your AppDelegate
Swift NFX.sharedInstance().start()

Invoke netfox UI Just shake your device and check what's going right or wrong! Shake again and go back to your app!
GitHub kasketis/netfox

Injection for Xcode Source

Injection is a plugin for Xcode that allows you to "inject" Objective-C and Swift code changes into a running application without having to restart it during development and testing. Injection no longer requires you to patch your project or it's sources for iOS projects in the simulator. To use: download this project, build it and restart Xcode. When your application is running type control-= and any modifications to the selected class should be applied to your application while it runs. That's it.
GitHub johnno1962/injectionforxcode

Profiling your Swift compilation times

The new iOS application that I’m working on – written 100% in Swift – was noticeably taking much longer to compile than should, given its size (~200 files). More concerning, it was suddenly a lot slower than only a couple of weeks prior. I needed to get to the root of the problem as soon as possible, before it got any worse.

Identify methods with slow compilation time and take action!

Add -Xfrontend -debug-time-function-bodies to my Swift compiler flags

Using the xcodebuild command line tool results in the logs being printed to standard output, where we can message them to our liking:
xcodebuild -workspace App.xcworkspace -scheme App clean build | grep [1-9].[0-9]ms | sort -nr > culprits.txt

You may also want to sort the result by the amount of times methods gets compiled:

awk -F '\t' '{print $2}' < culprits.txt | sort | uniq -c | sort -nr > culprits_count.txt
Best list compilation was to sort by the multiplication the time a method needs to get compiled with the …

FlatBuffers instead of JSON (or Protocol Buffers)

FlatBuffers is an efficient cross platform serialization library for C++, Java, C#, Go, Python and JavaScript (C, PHP & Ruby in progress). It was originally created at Google for game development and other performance-critical applications.

Why use FlatBuffers?

Access to serialized data without parsing/unpacking - What sets FlatBuffers apart is that it represents hierarchical data in a flat binary buffer in such a way that it can still be accessed directly without parsing/unpacking, while also still supporting data structure evolution (forwards/backwards compatibility).Memory efficiency and speed - The only memory needed to access your data is that of the buffer. It requires 0 additional allocations (in C++, other languages may vary). FlatBuffers is also very suitable for use with mmap (or streaming), requiring only part of the buffer to be in memory. Access is close to the speed of raw struct access with only one extra indirection (a kind of vtable) to allow for format evolution an…

Xcode 7.2: Refactoring not supported for Swift... but there is a plugin!

but... there is a plugin for that:

Refactorator GitHub

DeliciousRaspberryPi/MockFive - A Mocking Framework for Swift Unit Tests

MockFive allows you to make a single mock for a class or protocol. You can then configure instances of this mock with stubbed implementations. For any commonly used class, MockFive can offer a powerful means to satisfy Swift's strict typing system without sacrificing power. Because of Swift's strict typing, you must implement every method you intend to mock with calls to MockFive's stub().

// Optional types will return `nil` by defaultfuncmyFunc(arg1: Int, arg2: String) ->String? { return stub(identifier: "myFunc", arguments: arg1, arg2) } // Non-optional types require a default valuevar customItem = MyCustomClass() // This may be changed later. stub will return new valuefuncmyFunc() -> MyCustomClass { return stub(identifier: "myFunc") { customItem } }
MockFive GitHub

Swift on Android

Running Swift code on Android

The biggest issue here is going to be a missing SwiftCore library. Right now Apple is shipping one for iOS, OS X and Watch OS. But that's it - and obviously they don't ship an Android version.

However, not all Swift code requires the SwiftCore library, just like not all C++ code requires the STL. So as long as we use the subset of Swift that doesn't hit SwiftCore, we should be ok.

Romain Goyet

How to Use Apple Swift to Make an Android App
Our best course of action to get something working quickly was to take Swift code and compile it into Java source code — and then take it into the Android development environment to finish building it into an installable app. So we started in Xcode, where we wrote the Swift code. Then we tested it, including running it on an iPhone or in the iPhone Simulator, and ran a custom compiler that parsed the Swift code and output Java source code (adjusting any necessary syntax, and substituting appropriate Android cal…