Skip to content

Instantly share code, notes, and snippets.

View perlguy99's full-sized avatar

Brent Michalski perlguy99

  • Senior iOS Engineer
  • St. Louis, MO
View GitHub Profile
@perlguy99
perlguy99 / Xcode Run Script
Created January 3, 2017 20:28
Xcode Sign All Embedded Frameworks, works with projects that have spaces in them
OLSIFS=$IFS
IFS=$'\n'
for f in $(find $CODESIGNING_FOLDER_PATH -name '*.framework')
do
codesign --force --sign "${EXPANDED_CODE_SIGN_IDENTITY}" --preserve-metadata=identifier,entitlements --timestamp=none "$f"
done
IFS=$OLDIFS
@perlguy99
perlguy99 / Alamofire.request.error.handling.swift
Last active January 16, 2023 19:52
Alamofire Request Error Handling - From their documentation
Alamofire.request(urlString).responseJSON { response in
guard case let .failure(error) = response.result else { return }
if let error = error as? AFError {
switch error {
case .invalidURL(let url):
print("Invalid URL: \(url) - \(error.localizedDescription)")
case .parameterEncodingFailed(let reason):
print("Parameter encoding failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
String(data: dataVar, encoding: .utf8)
@perlguy99
perlguy99 / Xcode_Variables.txt
Created July 10, 2017 18:07
Xcode Environment variables
ACTION=build
AD_HOC_CODE_SIGNING_ALLOWED=NO
ALTERNATE_GROUP=staff
ALTERNATE_MODE=u+w,go-w,a+rX
ALTERNATE_OWNER=brent
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES=NO
ALWAYS_SEARCH_USER_PATHS=NO
ALWAYS_USE_SEPARATE_HEADERMAPS=NO
APPLE_INTERNAL_DEVELOPER_DIR=/AppleInternal/Developer
APPLE_INTERNAL_DIR=/AppleInternal
@perlguy99
perlguy99 / UI Main Thread
Created August 7, 2017 15:49
Operate on main thread
// Usage:
// UI {
// Anything in here will execute on the main thread
// }
func UI(_ block: @escaping ()->Void) {
DispatchQueue.main.async(execute: block)
}
@perlguy99
perlguy99 / BG Background Execution
Created August 7, 2017 15:49
BG Background Execution
// Usage:
// BG {
// Anything in here will execute in the background
// }
func BG(_ block: @escaping ()->Void) {
DispatchQueue.global(qos: .default).async(execute: block)
}
#define SCREEN_WIDTH ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.height)
#define SCREEN_HEIGHT ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.height : [[UIScreen mainScreen] bounds].size.width)
@perlguy99
perlguy99 / notificationTriggered.swift
Created December 23, 2018 02:19
Terrible, hacky notificationTriggered handler
@objc func notificationTriggered(_ notification: Notification) {
if let userInfo = notification.userInfo {
if let name = userInfo["name"] as? String {
if name == "CaretBlink" {
return
}
}
}
//
// IconTitleTextView.swift
//
// Created by Brent Michalski on 12/23/18.
// Copyright © 2018 Perlguy, Inc. All rights reserved.
//
// THIS CUSTOM CLASS PROPERLY LOADS FROM A STORYBOARD!!!
import UIKit
@perlguy99
perlguy99 / UIColor+hex.swift
Created January 8, 2019 16:44
UIColor extension for HEX values
extension UIColor {
convenience init?(hexString: String) {
var chars = Array(hexString.hasPrefix("#") ? hexString.dropFirst() : hexString[...])
let red, green, blue, alpha: CGFloat
switch chars.count {
case 3:
chars = chars.flatMap { [$0, $0] }
fallthrough
case 6:
chars = ["F","F"] + chars