Khoa Pham
Khoa Pham

Ohayo

Swift Discovery

Discover all the tech

Featured

My year in review 2020

Issue #715

I remember this time last year in December 2019, I spent almost every single bit of my free time on Puma because I want a Swift friendly version of fastlane that suits my need and leverages Swift 5 features.

Here’s my review of my …

How to use Timer in Swift

Issue #212

Pre iOS 10

func schedule() {
    DispatchQueue.main.async {
      self.timer = Timer.scheduledTimer(timeInterval: 20, target: self,
                                   selector: #selector(self.timerDidFire(timer:)), userInfo: nil, repeats: …

How to overload functions in Swift

Issue #211

Function

Functions in Swift are distinguishable by

  • parameter label
  • parameter type
  • return type

so that these are all valid, and works for subscript as well

struct A {

  // return type
  func get() -> String { return "" } …

Understanding AVFoundation and MediaPlayer frameworks in iOS

Issue #210

Depending on what features we want to achieve, we need to go with either AVFoundation or MediaPlayer framework. As someone who worked with many apps that involve media playback, here are some of my observations

MPMoviePlayerController vs …

How to handle reachability in iOS

Issue #209

Here are what I learn about reachability handling in iOS, aka checking for internet connection. Hope you will find it useful, too.

This post starts with techniques from Objective age, but many of the concepts still hold true

The naive way …

Dealing with CSS responsiveness in Wordpress

Issue #208

During the alpha test of LearnTalks, some of my friends reported that the screen is completely blank in the search page, and this happened in mobile only. This article is how I identify the problem and found a workaround for the issue, it …

How to build with xcodebuild and automatic code signing

Issue #207

Team ID

Error

Message: "xcodebuild: error: invalid option '-teamID'

Use =

xcodebuild teamID=T78DK947F3

Does not work 😢

DEVELOPMENT_TEAM

https://pewpewthespells.com/blog/migrating_code_signing.html

xcodebuild DEVELOPMENT_TEAM= …

How to launch app at start up in macOS

Issue #205

ServiceManagement framework

https://developer.apple.com/documentation/servicemanagement/1501557-smloginitemsetenabled

SMLoginItemSetEnabled

Enable a helper application located in the main application bundle’s “Contents/Library/LoginItems” …

How to fix mismatched deployment between app and test target in Xcode

Issue #204

  • My macOS app target has deployment target 10.12, but when running test, I get
Compiling for OS X 10.11, but module 'MyApp' has a minimum deployment target of OS X 10.12: …

How to notarize macOS app

Issue #203

New Notarization Requirements

https://developer.apple.com/news/?id=04102019a

With the public release of macOS 10.14.5, we require that all developers creating a Developer ID certificate for the first time notarize their apps, and that all …

How to resize image using imagemagick

Issue #202

mogrify -resize 1280x800 s2.png

How to use shared AppGroup UserDefaults in macOS and Xcode extension

Issue #201

  • Go to both app and extension target, under Capabilities, enable AppGroup

  • Specify $(TeamIdentifierPrefix)group.com.onmyway133.MyApp

  • $(TeamIdentifierPrefix) will expand to something like T78DK947F3., with .

  • Then using is like a …

How to check file under Library in macOS

Issue #200

let home = NSSearchPathForDirectoriesInDomains(.applicationScriptsDirectory, .userDomainMask, true).first!
let path = home.appending(".XcodeWayExtensions/XcodeWayScript.scpt")
let exists = FileManager.default.fileExists(atPath: …

How to parse json in Go

Issue #199

Unmarshal using encoding/json

  • property in struct needs to be first letter capitalized
import (
	"net/http"
	"encoding/json"
	"io/ioutil"
	"fmt"
)

type MyJsonObject struct {
	Id string `json:"id"` …

How to resolve deep json object in Dart

Issue #198

If we are not on the edge with GRPC and Protocol Buffer, then most likely we are going to deal with Restful and JSON. In one of my Flutter apps I needed to consume JSON

JSON and serialization

The guide at …

How to generate grpc protobuf files

Issue #197

protoc

https://grpc.io/docs/quickstart/go.html

Install the protoc compiler that is used to generate gRPC service code. The simplest way to do this is to download pre-compiled binaries for your platform(protoc--.zip) from here: …

How to cache CocoaPods

Issue #196

CocoaPods vs Carthage

CocoaPods will build and compile our frameworks every time whenever you are doing the clean build or run pod install or pod update for the project.

Cache Carthage …

How to build a networking in Swift

Issue #195

Miami

Concerns

Parameter encoding is confusing …

How to cancel DispatchWorkItem and NSOperation

Issue #194

DispatchWorkItem

How to construct URL with URLComponents and appendPathComponent in Swift

Issue #193

var components = URLComponents(string: "https://google.com/")
components?.path = "abc/"
components?.url

-> nil

var components = URLComponents(string: "https://google.com/")
components?.path = "/abc/" …

How to catch error in ApolloClient

Issue #192

Read https://www.apollographql.com/docs/react/features/error-handling How to catch actual error https://github.com/apollographql/apollo-client/issues/4016 🤔

import { Observable } from 'apollo-link'
import ApolloClient from …

Khoa Pham

Hello, I’m Khoa

I’m a thinker and storyteller with a passion for exploring the intersection of creativity and technology

🧑‍💻 I love crafting high quality and useful apps
🔥 I love open source. My GitHub open source has 2.3k followers with packages that are integrated by 45k+ apps and over 3.4m+ downloads on CocoaPods.
✍️ I write here on my blog and on Medium, which has over 2.7k+ followers with tons of articles and 90k+ monthly views.
🖥 Follow me for sharings about Swift, SwiftUI, iOS and macOS development.
Hei