Using Playground with CocoaPods

Issue #113 This is a follow up from my post Learning from Open Source: Using Playground on how to actually add a playground to your production project. The idea is simple: create a framework so that Playground can access the code. This demo an iOS project with CocoaPods. See the demo https://github.com/onmyway133/UsingPlayground This is also my question to this question https://stackoverflow.com/questions/47589855/how-to-expose-your-project-code-to-a-xcode-playground-when-using-cocoapods/47595120#47595120 1. Add a pod Create a new project called UsingPlayground....

December 1, 2017 · 2 min · 373 words · Khoa

URL Routing with Compass

Issue #110 Medium version https://medium.com/@onmyway133/url-routing-with-compass-d59c0061e7e2 Apps often have many screens, and UIViewController works well as the basis for a screen, together with presentation and navigation APIs. Things are fine until you get lost in the forest of flows, and code becomes hard to maintain. One way to avoid this is the central URL routing approach. Think of it as a network router that handles and resolves all routing requests. This way, the code becomes declarative and decoupled, so that the list component does not need to know what it’s presenting....

November 27, 2017 · 18 min · 3654 words · Khoa

Coordinator and FlowController

Issue #106 Every new architecture that comes out, either iOS or Android, makes me very excited. I’m always looking for ways to structure apps in a better way. But after some times, I see that we’re too creative in creating architecture, aka constraint, that is too far away from the platform that we’re building. I often think “If we’re going too far from the system, then it’s very hard to go back”...

November 14, 2017 · 11 min · 2169 words · Khoa

It's good to have a CI

Issue #101 I have Unit tests and UI tests pass on my simulator and device, locally. But when I make the build on Buddybuild, it fails with the reason Activity cannot be used after its scope has completed. People seem to have the same issue too. Taking a look at the log in Buddybuild t = 8.89s Staging: UIStatusBarWindow t = 8.95s Staging: (CoreFoundation) Sending Updated Preferences to System CFPrefsD t = 8....

November 2, 2017 · 3 min · 470 words · Khoa

Diff algorithm

Issue #99 I’ve been searching for efficient ways to diff collections, here are some interesting papers that I find Myers An O(ND) Difference Algorithm and Its Variations https://github.com/wokalski/Diff.swift https://github.com/kpdecker/jsdiff https://github.com/raywenderlich/swift-algorithm-club/pull/693/files Wu An O(NP) Sequence Comparison Algorithm https://github.com/kazuhiro4949/EditDistance https://github.com/cubicdaiya/onp https://github.com/hattya/go.diff/blob/master/diff.go https://gist.github.com/tociyuki/acedd33ca4913f1ab8e9 http://t2y.hatenablog.jp/entry/20090802/1249146010 Wagner–Fischer https://en.wikipedia.org/wiki/Wagner%E2%80%93Fischer_algorithm) http://davedelong.tumblr.com/post/134367865668/edit-distance-and-edit-steps https://github.com/osteslag/Changeset https://github.com/onmyway133/DeepDiff Common Longest Subsequence https://en.wikipedia.org/wiki/Longest_common_subsequence_problem https://github.com/jflinter/Dwifft https://github.com/Frugghi/SwiftLCS Heckel http://documents.scribd.com/docs/10ro9oowpo1h81pgh1as.pdf A technique for isolating differences between files https://github.com/mcudich/HeckelDiff IGListDiff https://github.com/andre-alves/PHDiff https://gist.github.com/ndarville/3166060 https://github.com/myndzi/heckel-diff https://johnresig.com/projects/javascript-diff-algorithm/ https://stackoverflow.com/questions/42755035/difficulty-understanding-paul-heckels-diff-algorithm https://github.com/RACCommunity/FlexibleDiff/blob/diffing/FlexibleDiff/Changeset.swift https://github.com/onmyway133/DeepDiff https://github....

October 31, 2017 · 1 min · 84 words · Khoa

How to use safeAreaLayoutGuide in iOS 10

Issue #98 The safeAreaLayoutGuide was introduced in iOS 11. And it is advised to stop using topLayoutGuide bottomLayoutGuide as these are deprecated. To use safeAreaLayoutGuide, you need to do iOS version check if #available(iOS 11.0, *) { headerView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20) } else { headerView.topAnchor.constraint(equalTo: view.topAnchor, constant: 20) } Maybe we can introduce a common property that can be used across many iOS versions, let’s call it compatibleSafeAreaLayoutGuide extension UIView { /// Use safeAreaLayoutGuide on iOS 11+, otherwise default to dummy layout guide var compatibleSafeAreaLayoutGuide: UILayoutGuide { if #available(iOS 11, *) { return safeAreaLayoutGuide } else { if let layoutGuide = self....

October 31, 2017 · 1 min · 186 words · Khoa

Learning from Open Source Using Coordinator

Issue #97 The Coordinator pattern can be useful to manage dependencies and handle navigation for your view controllers. It can be seen from BackchannelSDK-iOS, take a look at BAKCreateProfileCoordinator for example @implementation BAKCreateProfileCoordinator - (instancetype)initWithUser:(BAKUser *)user navigationController:(UINavigationController *)navigationController configuration:(BAKRemoteConfiguration *)configuration { self = [super init]; if (!self) return nil; _navigationController = navigationController; _user = user; _profileViewController = [[BAKProfileFormViewController alloc] init]; [self configureProfileForm]; _configuration = configuration; return self; } - (void)start { [self....

October 25, 2017 · 1 min · 124 words · Khoa

Learning from Open Source Managing dependencies

Issue #96 Another cool thing about ios-oss is how it manages dependencies. Usually you have a lot of dependencies, and it’s good to keep them in one place, and inject it to the objects that need. The Environment is simply a struct that holds all dependencies throughout the app /** A collection of **all** global variables and singletons that the app wants access to. */ public struct Environment { /// A type that exposes endpoints for fetching Kickstarter data....

October 25, 2017 · 3 min · 440 words · Khoa

Learning from Open Source Using Playground

Issue #94 One thing I like about kickstarter-ios is how they use Playground to quickly protoyping views. We use Swift Playgrounds for iterative development and styling. Most major screens in the app get a corresponding playground where we can see a wide variety of devices, languages and data in real time. This way we don’t need Injection or using React Native anymore. Take a look at all the pages https://github.com/kickstarter/ios-oss/tree/master/Kickstarter-iOS.playground/Pages...

October 23, 2017 · 1 min · 87 words · Khoa

Testing keychain in iOS

Issue #92 Today I was upgrading Keychain to swift 4, and take this opportunity to fix the test. The tests pass on macOS, but on iOS, I get -25300 error for var status = SecItemCopyMatching(query as CFDictionary, nil) It is because there is no Keychain entitlement for test target. But this is a framework, how can I add entitlement 🤔 The solution is to use a Test Host to host the XCTest tests....

October 20, 2017 · 1 min · 157 words · Khoa

Designing for iPhone X

Issue #90 http://blog.maxrudberg.com/post/166045445103/ui-design-for-iphone-x-top-elements-and-the-notch https://designcode.io/ios11-iphone-x https://medium.muz.li/ui-design-tips-for-iphone-x-2652b2b248ce

October 19, 2017 · 1 min · 5 words · Khoa

What about performance?

Issue #85 That’s the question I hear often when people are introduced to a new framework. It’s a valid concern. But it seems to me that they ask this just for fun. To my surprise, most people just don’t care, and the frameworks with the most stars often perform the worst. Now take a look back at performance. Here are some benchmarks From https://github.com/ibireme/YYModel, compare different JSON mappers for ObjC...

October 10, 2017 · 2 min · 280 words · Khoa

How to do implement notification in iOS with Firebase

Issue #64 Note: This applies to Firebase 4.0.4 Preparing push notification certificate Go to Member Center -> Certificates -> Production Certificate You can now use 1 certificate for both sandbox and production environment Auth Key If you like to use Auth Key, read Provider Authentication Tokens Configure push notification Go to Firebase Console -> Settings -> Project Settings -> Cloud Messaging -> iOS app configuration If you use certificate, use just 1 Apple Push Notification service SSL for both fields If you use Authenticate Key, fill in APNS auth key Adding pod In your Podfile, declare...

August 9, 2017 · 2 min · 331 words · Khoa

Pixel and point

Issue #59 TL;DR: Don’t use nativeScale and nativeBounds, unless you’re doing some very low level stuff What is point and pixel From https://developer.apple.com/library/content/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html In iOS there is a distinction between the coordinates you specify in your drawing code and the pixels of the underlying device The purpose of using points (and the logical coordinate system) is to provide a consistent size of output that is device independent. For most purposes, the actual size of a point is irrelevant....

June 16, 2017 · 3 min · 433 words · Khoa

Favorite WWDC 2017 sessions

Issue #56 Source WWDC 2017 Introducing Core ML Core ML Introducing ARKit: Augmented Reality for iOS ARKit What’s New in Swift String Generic Codable Advanced Animations with UIKit Multiple animation Interactive animation Natural Language Processing and your Apps NSLinguisticTagger What’s New in Cocoa Touch Large title Drag and drop File management Safe area What’s New in Foundation KeyPath Observe Codable Debugging with Xcode 9 Wireless debugging View controller debugging Core ML in depth Model Core ML tools Vision Framework: Building on Core ML Detection Track What’s New in Testing Parallel testing Wait Screenshot Multiple app scenario

June 10, 2017 · 1 min · 96 words · Khoa

How to run UITests with map view in iOS

Issue #45 Mock a location You should mock a location to ensure reliable test Create the gpx file Go to Xcode -> File -> New -> GPX File It looks like <?xml version="1.0"?> <gpx version="1.1" creator="Xcode"> <wpt lat="59.913590" lon="10.733750"> <name>Oslo S</name> <time>2017-05-31T14:55:37Z</time> </wpt> <wpt lat="59.913590" lon="10.733750"> <name>Oslo S</name> <time>2017-05-31T14:55:40Z</time> </wpt> </gpx> The gpx file is very powerful, as it allows you to specify a route with different movement speed. Provide one or more waypoints containing a latitude/longitude pair....

June 1, 2017 · 2 min · 371 words · Khoa

How to use MainController in iOS

Issue #36 Usually in an app, we have these flows: onboarding, login, main. And we usually set OnboardingController, LoginController and MainController as the root view controller respectively depending on the state. I find it useful to have the MainController as the container for main flow. It can be a tab controller, swipe menu controller or contains just 1 child view controller. The screens are provided by child view controllers, but the MainController does the following jobs...

May 12, 2017 · 1 min · 194 words · Khoa

How to handle Auto Layout with different screen sizes

Issue #35 Auto Layout is awesome. Just declare the constraints and the views are resized accordingly to their parent ’s bounds changes. But sometimes it does not look good, because we have fixed values for padding, width, height, and even fixed font size. Read more How to make Auto Layout more convenient in iOS This can be solved by some degree using Size Class. The idea of size class is that we have many sets of constraints, and based on the device traits, we enabled some of them....

May 12, 2017 · 2 min · 396 words · Khoa

How to define SDK and Deployment Target in iOS

Issue #33 I see that my answer to the question What’s the meaning of Base SDK, iOS deployment target, Target, and Project in xcode gets lots of views, so I think I need to elaborate more about it Good read iOS 7 TechTalk - Architecting Modern Apps, Part 2 Configuring a Project for SDK-Based Development Base SDK We can’t configure this anymore, as Xcode will use the latest SDK. For Xcode 7, the SDK is iOS 9 If we upgrade Xcode, it will use the newer version of the SDK....

May 10, 2017 · 4 min · 701 words · Khoa

App backed by website in iOS 9

Issue #32 iOS 9 introduces new ways for your app to work better, backed by your websites Smart App Banners Promoting Apps with Smart App Banners If the app is already installed on a user’s device, the banner intelligently changes its action, and tapping the banner will simply open the app. If the user doesn’t have your app on his device, tapping on the banner will take him to the app’s entry in the App Store...

May 10, 2017 · 2 min · 331 words · Khoa