I found myself having to google this multiple times so I decide to write it here as a quick references for myself.
Git submodules is a way for you to keep a git repository as a subdirectory of another git repository. It’s useful when you want to incorporate and keep track of external code or framework that your project depends on. It’s like a poor man’s version of npm or cocoapods.
Anyway, to add a git submodules is very easy. It’s just simple a one liner. Eg:
That’s it. But the steps to remove it are very tedious and it’s something that I always forgot how to. So here are the steps to completely remove it from your repository.
Cloud SQL Proxy is one of the ways to connect to your Cloud SQL instance. It’s useful if you want to securely connect to Cloud SQL from your local applications.
Here are the steps to setup Cloud SQL Proxy on your local machines:
A service account is a special type of Google account that belongs to your project. Instead of using your individual user’s credential, you can use service account to authenticate your application.
To set it up, follow these commands. You can replace "my-proxy-user" to your likings
$~ gcloud iam service-accounts create proxy-user --display-name "my-proxy-user"
Once you have created it, list it down to get the email of the service account.
$~ gcloud iam service-accounts list
Next, allow your service account to connect to the Cloud SQL proxy on your behalf. You can do this by giving Cloud SQL Client role to the service account.
Run the following commands. Replace [PROJECT_ID] and [SERVICE_ACCOUNT_EMAIL] with your own Google Project ID and the service account email that you got from the command before.
Finally to start the Cloud SQL Proxy, run the following commands. Replace the [INSTANCE_CONNECTION_NAME] with your own and the [PORT] based on the database you want to connect to.
listen tcp 127.0.0.1:5432: bind: address already in use
It’s likely you already have a local database instance running on your local machine that’s using the port 5432 (In this case it’s Postgresql). If this is the case, stop the running instance first.
Today I learned that you can actually create multiple Xcode screen previews in SwiftUI.
Assuming you have a SwiftUI View named ContentView. In the PreviewProvider, create a Group and init multiple ContentView() children inside of it. For example:
Did you know that SwiftUI can be use in UIKit project? To use SwiftUI in UIKit project, you have to make use of UIHostingViewController. It is a UIViewController that basically “host” a SwiftUI view.
Assuming you have a SwiftUI View named SwiftUIView like so:
To add a new package with Swift Package Manager is really easy. Go to the following Xcode’s menu:
File > Swift Packages > Add Package Dependency...
and add the package’s repository URL. That’s it.
For example, to add Alamofire library you just have to add https://github.com/Alamofire/Alamofire.git in the search field.
You then will have the option to configure the package based on the version, branch or even commit.
Once you have chosen the package target, you will noticed the newly added package at the bottom of Xcode’s Project Navigator. Now, you can import the package as usual.
To remove a package is easy too. Navigate to your project settings and you will noticed that there is a new section called Swift Packages. Navigate to it, click on your library and click on the minus button below to remove it.
From my limited understanding of how it works, I was expecting Swift Package Manager to create a Package.swift file but instead it creates a references of the package in .xcodeproj file.
Based on my experience of how painful it is to solve a merge conflict in .xcodeproj file, this is definitely something that I probably would think twice before using it in a team project. Otherwise, using Swift Package Manager is really easy.
Hey, no rubygems dependencies is already a plus! 😉