IOS Pushkit integration

Posted on 06 Kasım 2018 in Programlama by

Necessary tools:
https://github.com/noodlewerk/NWPusher

How to make a c++ class singleton easily

Posted on 06 Kasım 2018 in Programlama by

https://sourcemaking.com/design_patterns/to_kill_a_singleton

Refactoring singleton usage in Swift

Posted on 06 Kasım 2018 in Programlama by

In this post, it is explained how to properly use of singleton in view controllers. It basically uses dependency injection on singleton instances.
https://www.jessesquires.com/blog/refactoring-singletons-in-swift/

IOS introduction to delegates

Posted on 04 Kasım 2018 in Programlama by

Understanding Delegates and Delegation in Swift 4

Concurrent vs serial queues in GCD

Posted on 03 Kasım 2018 in Programlama by

There is a good conversation here
https://stackoverflow.com/questions/19179358/concurrent-vs-serial-queues-in-gcd

An example to running sync call and async queue. Sync task in a different queue blocks current caller thread.
You have two guys – Bob and Mark. Bob makes dough and gives it to Mark to put in the oven. And here you can have two scenarios, either Bob will wait with making next batch of dough until Mark puts current batch in the oven (this would be sync) or he will start right away and won’t bother if Mark did his job already (async)
It may sound like sync does not make sense – what’s the point of concurrency if you have to wait for other thread to finish its work? But actually it has some valid applications. As you know, all UI calls need to be performed on main thread. Let’s assume you have some code which runs in background queue and from time to time it needs to check if app is in the background or foreground. It can be done by asking UIApplication for applicationState, yet calling it from background thread might cause crash or at least a threading warning. So the solution is:

let applicationState = DispatchQueue.main.sync { return UIApplication.shared.applicationState }

This will block current queue until main queue returns this value. You can’t use async here as you need this value to continue your work. Analogy for Bob and Mark would be waiting for Mark to tell Bob if there is still space in the oven for next batch of cake, so Bob can decide if he should make it or not 😉

Finding top view controller in swift

Posted on 11 Ekim 2018 in Programlama by

How to find visible view controller?

    func topMostController() -> UIViewController {
        var topController = UIApplication.shared.keyWindow?.rootViewController
        while (topController?.presentedViewController != nil) {
            topController = topController?.presentedViewController
        }
        return topController!
    }
    
    func topViewController(_ controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
        if let navigationController = controller as? UINavigationController {
            return topViewController(navigationController.visibleViewController)
        }
        if let tabController = controller as? UITabBarController {
            if let selected = tabController.selectedViewController {
                return topViewController(selected)
            }
        }
        if let presented = controller?.presentedViewController {
            return topViewController(presented)
        }
        return controller
    }

Thread safe variable usage in singleton (IOS-swift)

Posted on 04 Ekim 2018 in Programlama by

class Singleton {
    static var shared = Singleton()
    private let internalQueue = DispatchQueue(label: "SingletionInternalQueue", qos: .default, attributes: .concurrent)

    private var _foo: String = "aaa"

    var foo: String {
        get {
            return internalQueue.sync { _foo }
        }
        set (newState) {
            internalQueue.async(flags: .barrier) { self._foo = newState }
        }
    }

    func setup(string: String) {
        foo = string
    }
}

Thread safety is accomplished by having a computed property foo which uses an internalQueue to access the “real” _foo property.

Also, in order to have better performance internalQueue is created as concurrent. And it means that it is needed to add the barrier flag when writing to the property.

What the barrier flag does is to ensure that the work item will be executed when all previously scheduled work items on the queue have finished.

https://stackoverflow.com/questions/49160125/thread-safe-singleton-in-swift

Must have iOS libraries

Posted on 10 Eylül 2018 in Programlama by

https://medium.com/app-coder-io/27-ios-open-source-libraries-to-skyrocket-your-development-301b67d3124c
Especially I love https://github.com/dzenbot/DZNEmptyDataSet

Action sheet controller
https://github.com/xmartlabs/XLActionController?utm_source=mybridge&utm_medium=blog&utm_campaign=read_more

Expanding collection
https://github.com/Ramotion/expanding-collection?utm_source=mybridge&utm_medium=blog&utm_campaign=read_more

Swift algorithms
https://github.com/raywenderlich/swift-algorithm-club

IOS library collection
https://github.com/matteocrippa/awesome-swift

ios swift mvvm tutorials

Posted on 02 Ağustos 2018 in Programlama by

You can find useful mvvm tutorials below:
https://medium.com/flawless-app-stories/how-to-use-a-model-view-viewmodel-architecture-for-ios-46963c67be1b
https://medium.com/@azamsharp/mvvm-in-ios-from-net-perspective-580eb7f4f129

A good video from raywenderlich

Aes encryption

Posted on 29 Haziran 2018 in Programlama by

http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html