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 …

Getting activity name through HKWorkoutActivityType in HealthKit

Issue #186

After fetching workouts with HKObjectType.workoutType() , we get HKWorkoutActivityType , which is an enum enum HKWorkoutActivityType : UInt . As of Swift 4.2, there are no way to get enum case as String because this enum has type UInt . …

Curry in Swift and Javascript

Issue #185

You may encounter curry in everyday code without knowing it. Here is a bit of my reflections on curry and how to apply it in Javascript and Swift.

Taking one parameter in Haskell

In Haskell, all function officially takes only 1 parameter. …

How to fix SSLPeerUnverifiedException in Android

Issue #184

Get error javax.net.ssl.SSLPeerUnverifiedException: No peer certificate in Android API 16 to API 19

Getting started

Read about HTTPS and SSL https://developer.android.com/training/articles/security-ssl Check backend TLS …

How to zoom in double in MapKit

Issue #183

func zoomInDouble(coordinate: CLLocationCoordinate2D) {
    let region = mapView.region
    let zoomInRegion = MKCoordinateRegion(
        center: coordinate,
        span: MKCoordinateSpan(
            latitudeDelta: region.span. …

How to select cluster annotation in MapKit

Issue #182

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    guard let coordinate = view.annotation?.coordinate else {
        return
    }
    
    if (view.annotation is MKClusterAnnotation) {
        zoomInDouble( …

How to cluster annotations in MapKit in iOS 11

Issue #181

https://developer.apple.com/documentation/mapkit/mkannotationview/decluttering_a_map_with_mapkit_annotation_clustering

final class AnnotationView: MKMarkerAnnotationView {
    override init(annotation: MKAnnotation?, reuseIdentifier: …

Understanding CanvasRenderingContext2D and UIBezierPath

Issue #180

CanvasRenderingContext2D

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/bezierCurveTo

The CanvasRenderingContext2D.bezierCurveTo() method of the Canvas 2D API adds a cubic Bézier curve to the current sub-path. …

How to get properties of JSValue in JavascriptCore

Issue #179

let rough = context.objectForKeyedSubscript("myObject")
myObject.toDictionary()

How to run ffmpeg in macOS app

Issue #178

Install ffmpeg, which installs ffprobe

brew install ffmpeg

Find location of installed ffmpeg

which ffmpeg

Add all executables to project

Get error

unable to obtain file audio codec with ffprobe

Run in verbose mode

ffmpeg -v

Get

[debug] …

How to get path to resource in running macOS app

Issue #177

This is useful to refer to another executable in a running executable in Process

Bundle.main.path(forResource: "ffmpeg", ofType: "")!

How to run executable in macOS

Issue #176

Enable executable

chmod +x executable

Add executable file to target Use Process with correct launchPad

import Foundation

protocol TaskDelegate: class {
  func task(task: Task, didOutput string: String)
  func taskDidComplete(task: Task)
} …

How to print current directory using Process in macOS

Issue #175

let process = Process()
process.launchPath = "/bin/pwd"
process.arguments = []

Should be the same as FileManager.default.currentDirectoryPath

How to change NSTextField backgroundColor in NSPopover

Issue #174

Disable vibrancy mode of NSPopover

let popover = NSPopover()
popover.appearance = NSAppearance(named: NSAppearance.Name.aqua)

How to make scrollable vertical NSStackView

Issue #173

You might need to flip NSClipView

import AppKit
import Anchors
import Omnia

final class ScrollableStackView: NSView {
    final class FlippedClipView: NSClipView {
        override var isFlipped: Bool {
            return true
        } …

How to make view take up full width in vertical NSStackView

Issue #172

https://stackoverflow.com/questions/51644692/nsstackview-subviews-not-resizing-sub-stack-views/55220837#55220837

If you want child view inside vertical NSStackView to fill its parent width, then reduce contentCompressionResistancePriority …

How to load top level view from xib in macOS

Issue #171

var views: NSArray?
NSNib(nibNamed: NSNib.Name("ProfileView"), bundle: nil)?.instantiate(withOwner: nil, topLevelObjects: &views)
let profileView = views!.compactMap({ $0 as? ProfileView }).first!

How to fix MethodError - undefined method `real_path` with CocoaPods?

Issue #170

abc

I’m using cocoapods 1.6.0.beta.2 in a React Native apps and it has been working fine. The pods that I need is Firebase and FacebookSDK. Today after pod install, I got error

NoMethodError - undefined method `real_path' for …

Testimonial

Issue #169

https://medium.com/@kylpo/wow-i-learned-so-much-from-this-article-thank-you-595f29077633 …

Understanding weak and strong in Objective C

Issue #164

From my own blog post https://github.com/Fantageek/fantageek.github.io/blob/source/source/_posts/2014-06-27-understanding-weak-self-and-strong-self.markdown


Blocks are wonderful. To avoid retain cycle you often see the weakSelf - …

Interesting, how did you managed to plug GitHub issues into the dev.to platform

Issue #163

I’ve found your post https://dev.to/onmyway133/changing-electron-app-icon and fist thought there is some static site generator which uses GitHub’s issues as a datasource.

Am I right?

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