Skip to content

Instantly share code, notes, and snippets.

View SheldonWangRJT's full-sized avatar
🎯
Focusing

Engineer Sheldon Wang SheldonWangRJT

🎯
Focusing
View GitHub Profile
@SheldonWangRJT
SheldonWangRJT / Convert .mov or .MP4 to .gif.md
Last active April 15, 2024 20:14
Convert Movie(.mov) file to Gif(.gif) file in one command line in Mac Terminal

This notes is written by Sheldon. You can find me with #iOSBySheldon in Github, Youtube, Facebook, etc.

Need

Convert .mov/.MP4 to .gif

Reason

As a developer, I feel better to upload a short video when I create the pull request to show other viewers what I did in this PR. I tried .mov format directly got after finishing recording screen using Quicktime, however, gif offers preview in most web pages, and has smaller file size.

This is not limited to developer, anyone has this need can use this method to convert the files.

@SheldonWangRJT
SheldonWangRJT / iOS Dynamic vs. Static Library & Framework.md
Last active November 14, 2022 04:07
iOS Dynamic vs. Static Library / Framework

iOS Dynamic vs. Static Library / Framework

Find me on Github, Facebook, Youtube, etc by #iOSBySheldon.

Concept

Library and Framework are not same but close. Frameworks are just libraries with linking (binding). In other words, frameworks are just libraries that are bundled into targets. Therefore, their file extensions are different.

File Format

  • Static Library - xxxx.a
  • Dynamic Library - xxxx.dylib
@SheldonWangRJT
SheldonWangRJT / iOS Create a Carthage Supported Framework.txt
Last active August 28, 2023 09:28
iOS Create a Carthage Supported Framework
iOS Create a Carthage Supported Framework
#iOSBySheldon
A little bit Background of Carthage:
- Carthage works like Cocoapods, but a little bit simpler.
* When creating a Cocoapods supported framework need a .podspec file to do some config, which is not required by Carthage.
* When using a Cocoapods supported framework, a workspace file will be automatically created, the umbrella header will be setup in a pod project inside workspace. It feels simple, but the whole process creates a lot files including a "giant" workspace.
* When using a Carthage supported framework, it will just download the framework, and its dependencies if any, to a folder. All we need to do is to drag and drop it to the binary linking section in the project build setting tab, for the first time. It sounds complicated but it makes the project clean.
- Carthage is written in Swift.
- Carthage internally uses `-xcodebuild` to build dependency.
@SheldonWangRJT
SheldonWangRJT / Git - Revert a Merge.txt
Last active March 5, 2019 20:45
Git - Common Used Commands
Git - Revert a Merge
#iOSBySheldon
Reverting a commit is usually not hard, specially with the help of Source Tree, if, you are reverting a simple commit on a branch. What you need to do is just to right click the commit you want to revert and then choose "Reverse Commit".
However, if the commit you want to revert is a "Merge", it will be a little bit harder. If you do the same thing in Source Tree, right click - "Reverse Commit", it will give you an error that Source Tree cannot revert it because there are two branches involved.
Let's name the merge-from branch as "F" and "merge-to" branch as "T".
Here is the solution for it (only can be done in Terminal, at least today):
#iOSBySheldon
Apple LLVM 9.0 - Language - C++ Settings
This is an option setting under a Target - Build Settings tab. The idea is to let Xcode (LLVM) to be able to handle C++ functions, if you are using any static framework that is written in C++.
This is two items that need to be selected(it may be defaulting different values by different Xcode version):
C++ Language Dialect: GNU++14 [-std=gnu++14]
C++ Standard Library: libc++ (LLVM c++ standard library with C++11 support)
14 indicates this version came out in 2014 [1], if you have to use older version, 11 is in the droplist. If you need 98 you can still run some script to achieve it. [2]
@SheldonWangRJT
SheldonWangRJT / Something About iOS Crashes.md
Last active August 4, 2018 21:35
Dealing with the Crash Log Files (.crash), dSYM, EXC_BAD_ACCESS, EXC_CRASH and so on.

Something About iOS Crashes

#iOSBySheldon Apps are crashing all the time. No matter how good you write your app, it will crash in some cases.

When apps crashed, iOS will automatically generate a crash log file, the file has the extension as .crash. A crash file contains a lot of info like which version, which build, which device your app is crashing on. And the most important part of a crash file a the stack trace that indicates which function of your code in which file is crashing.

However, to find out which function of your code is crashing is not that straight forward from the crash log files. Because when we build our app, Xcode compiles our code files into binaries that changes the looking of our code. Therefore, to find out which line of code is crashing, we need a file to kinda to the translation for us, in iOS, this "translation" needs to be handled by debug-symbols files, which is also called dSYM files. (.dSYM)

Please see [1] as the image that indicates the whole process of creating the bu

@SheldonWangRJT
SheldonWangRJT / Something About NSUserDefaults.txt
Last active February 13, 2018 21:26
Something About NSUserDefaults
Something About NSUserDefaults
#iOSBySheldon
As an iOS developer, you must have heard NSUserDefaults, because, it is one of the easiest way to store something locally in users device. Even you have known it, this quick post may still help you know some details. [1]
1. NSUserDefaults is just a plist file.
Although Apple has built the interface to use it, the core of NSUserDefaults is just a plist file. The interface is pretty straight forward
UserDefaults.standard.set(<#T##value: Any?##Any?#>, forKey: <#T##String#>)
Git Cancel Commit Before Push
#iOSBySheldon
Sometimes, we have committed something and then we regret and don't want to push it anymore. In case of this, we can discard our commit, which is better done in terminal, I mean, SourceTree is limited sometime.
There are multiple ways to do this, you can rebase, you can reset, today, I will use reset.
1. Soft reset
$ git reset --soft HEAD^
@SheldonWangRJT
SheldonWangRJT / Map, FlatMap (CompactMap), Reduce, Filter & Sort.md
Last active March 21, 2022 20:04
Swift Map, FlatMap (CompactMap), Reduce, Filter & Sort

High Order Functions in iOS Swift

Written by Sheldon, please find me with #iOSBySheldon in Github, Youtube, Facebook, etc.

It is exaggerating to say we don't need to use for loop or while loop any more but we can take advantage of the Swift language built in functions to do loops. If I give you a question now. Q: Assuming we have an optional nested array, please calculate the production of the values that are less than 5. let numbers: [[Int]?] = [[1, 3], nil, [2], [5, 10], nil, [4]], what is your best approach to do it?

And you know the solution that I am talking about is following Swift functions:

  1. Map
  2. FlatMap / CompactMap

iOS Swift - Cancellable Task with GCD

#iOSBySheldon

I think most of you guys know GCD pretty well. Basically, GCD is a high level API to handle multi-threading operations. We use GCD almost on daily basis to switch thread and execute codes like:

DispatchQueue.main.async { //execute some codes here } 
//switch to main queue and execute codes asynchronously

DispatchQueue.main.sync { //execute some codes here } 
//switch to main queue and execute codes synchronously