Skip to content

Instantly share code, notes, and snippets.

@vvit
vvit / swizzling.swift
Last active November 23, 2017 09:10
Swizzling
// AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIViewController.doSwizzleStuff()
}
// extension
// MARK: - Swizzling
private var hasSwizzled = false
extension UIViewController {
@vvit
vvit / UI.swift
Last active October 14, 2017 21:39
// Check if a view controller is popped from navigation stack (either by `popViewController` or interactive transition)
// Method 1
override func didMove(toParentViewController parent: UIViewController?) {
super.didMove(toParentViewController: parent)
if parent == nil { // parent is `nil` when the vc is popped
}
}
// Method 2
override func viewDidDisappear(animated: Bool) {
@vvit
vvit / EGO theme
Last active November 22, 2017 21:29
mkdir -p ~/Library/Developer/Xcode/UserData/FontAndColorThemes;
cd ~/Library/Developer/Xcode/UserData/FontAndColorThemes;
curl -O https://dl.dropboxusercontent.com/u/1983175/EGOv2.dvtcolortheme
Now just restart Xcode, go to Preferences > Fonts & Colors, and select "EGO" or "EGOv2" from the color theme drop down.
http://developers.enormego.com/view/ego_xcode_theme_for_xcode_4_egov2
@vvit
vvit / Memo.swift
Last active September 21, 2017 14:00
// Singleton
final class Singleton {
static let shared = Singleton()
private init() { // forbid object creation
}
}
// Lazy
lazy var players = {
// Version check:
sudo gem list cocoapods
// Downgrade
sudo gem uninstall cocoapods
// Install required version
sudo gem install cocoapods -v 0.25.0
@vvit
vvit / gsutil
Created March 19, 2015 17:40
Google Storage Util
//listing
gsutil ls gs://arq-285486884533/
//size
gsutil du -sh gs://arq-285486884533/
@vvit
vvit / Reset Push Alert
Last active August 29, 2015 14:16
Resetting the Push Notifications Permissions Alert
1. Delete your app from the device.
2. Turn the device off completely and turn it back on.
3. Go to Settings > General > Date & Time and set the date ahead a day or more.
4. Turn the device off completely again and turn it back on.
https://developer.apple.com/library/ios/technotes/tn2265/_index.html#//apple_ref/doc/uid/DTS40010376-CH1-TNTAG42
@vvit
vvit / Podfile
Created January 30, 2015 10:25
Podfile: Add Preprocessor Macro
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
if target.name == 'Pods-Mixpanel'
target.build_configurations.each do |config|
if config.name == 'Debug'
puts " Pods-Mixpanel #{config.name} before: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].inspect}"
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'DISABLE_MIXPANEL_AB_DESIGNER=1'
puts " Pods-Mixpanel #{config.name} after: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].inspect}"
end
@vvit
vvit / git
Last active November 22, 2017 21:28
Frequently used commands
//If git keeps asking the passkey: add it to the keychain
ssh-add -K ~/.ssh/id_rsa
//create and switch to a new branch
git checkout -b <branch>
//push new branch to a repo
git push -u origin <branch>
@vvit
vvit / Constraint.swift
Last active September 23, 2016 14:06
Constraint animation
view.layoutIfNeeded() // Optional. Ensure that all pending layout operations have been completed
UIView.animateWithDuration(5) {
someConstraint.constant = 0
self.view.layoutIfNeeded() // called on parent view
}