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 login with Apple in SwiftUI

Issue #808

Make SignInWithAppleButton

Wrap ASAuthorizationAppleIDButton inside UIViewRepresentable

import SwiftUI
import UIKit
import AuthenticationServices

struct SignInWithAppleButton: View {
    @Environment(\.colorScheme)
    private var …

How to use SwiftLint in SPM project

Issue #807

Don’t add SwiftLint via SPM, but just add a Run Script Build phrase

if which swiftlint >/dev/null; then
  swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi …

How to show modal window in AppKit

Issue #806

Use runModal

https://developer.apple.com/documentation/appkit/nsapplication/1428590-runmodalsession

Blocks main queue

A loop that uses this method is similar in some ways to a modal event loop run with runModal(for:), except with this …

How to perform action during long press in SwiftUI

Issue #805

Use LongPressGesture to detect when long-press gesture has been recognized, and chain with DragGesture to check when pressing still occurs

Image(systemName: SFSymbol.deleteLeft.rawValue)
    .imageScale(.medium)
    .onTapGesture { …

How to fallback img in React

Issue #804

<img 
    src={user.avatarUrl} 
    onError={(e) => {
        e.target.onerror = null; 
        e.target.src = "/images/default.png"
    }}
/>

Extract to React Component

interface Props {
    src: string
    className: …

How to use videojs in React

Issue #803

import React from 'react';
import videojs from 'video.js'
import 'video.js/dist/video-js.css';

export default class VideoPlayer extends React.Component {
    createPlayer() {
        // instantiate Video.js …

How to use FontAwesome 5 in Nextjs

Issue #802

npm i --save @fortawesome/fontawesome-svg-core \
             @fortawesome/free-solid-svg-icons \
             @fortawesome/free-brands-svg-icons \
             @fortawesome/react-fontawesome
import { faApple, faGithub, faTwitter } from …

How to use Bulma in Nextjs

Issue #801

Read

npm install bulma sass

In styles/index.scss

@import '~bulma/bulma';

In _app.tsx

import '../styles/index.scss'

How to make your apps stand out on the AppStore

Issue #799

Besides coming up with a good idea and building the app, there are many other things you can do to boost your apps’ visibility

Twitter thread https://twitter.com/onmyway133/status/1387851727714635776 Thread reader …

How to use SwiftGen and LocalizedStringKey in SwiftUI

Issue #798

swiftgen.yml

strings:
  inputs: PastePal/Resources/Localizable/en.lproj
  outputs:
    - templatePath: swiftgen-swiftui-template.stencil
      output: PastePal/Resources/Strings.swift

Template from …

How to localize SwiftUI projects

Issue #797

Reference

How to use ForEach with indices in SwiftUI

Issue #796

One seemingly obvious way to use ForEach on array with indices is using enumerated

struct Book: Hashable, Identifiable {
    let id: UUID
    let name: String
}

struct BooksView: View {
    let books: [Book]

    var body: some View { …

How to resize NSImage with padding

Issue #795

extension NSImage {
    func resize(width: CGFloat, height: CGFloat, padding: CGFloat) -> NSImage {
        let img = NSImage(size: CGSize(width: width, height: height))

        img.lockFocus()
        let ctx = NSGraphicsContext. …

How to convert from paid to freemium in SwiftUI with RevenueCat

Issue #794

I’ve been distributing my apps PastePal and Push Hero as a paid upfront apps on Appstore. I’ve quickly come to realize the importance of trials since many have requested a tryout before purchasing.

Manual sending out trials …

How to repeat array of object in Swift

Issue #793

To create array containing number of repeated value in Swift, we can use Array.init(repeating:count:)

let fiveZs = Array(repeating: "Z", count: 5)
print(fiveZs)
// Prints "["Z", "Z", "Z", "Z", …

How to use dynamic color in iOS

Issue #792

iOS 13 introduced Dark Mode with User Interface Style that makes it easy to support dark and light theme in our apps. Before we dive in, here are some official resources

How to use View protocol in SwiftUI

Issue #791

SwiftUI has View protocol which represents part of your app’s user interface and provides modifiers that you use to configure views.

You create custom views by declaring types that conform to the View protocol. Implement the required …

How too save image to Photo library in iOS

Issue #790

Use UIImageWriteToSavedPhotosAlbum

Adds the specified image to the user’s Camera Roll album.

Let’s make an NSObject delegate class so we can perform target action to notify about completion

import UIKit

struct ImageService { …

How to manage WindowGroup in SwiftUI for macOS

Issue #789

Using WindowGroup

New in SwiftUI 2.0 for iOS 14 and macOS 11.0 is WindwGroup which is used in App protocol. WindowGroup is ideal for document based applications where you can open multiple windows for different content or files. For …

How to show img tag from GitHub markdown in Hugo

Issue #788

I just convert my blog https://onmyway133.com/ from Hexo.js back to Hugo again. Hugo now uses goldmark as the default markdown processor instead of blackfriday

All works well, except that I use GitHub markdown to write articles, which use …

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