Skip to content

Instantly share code, notes, and snippets.

View tonyarnold's full-sized avatar

Tony Arnold tonyarnold

View GitHub Profile
@tonyarnold
tonyarnold / gist:2010649
Created March 10, 2012 07:22
Exhaustively check if an Objective-C object is "empty"
static inline BOOL CBIsEmpty(id obj) {
return obj == nil
|| (NSNull *)obj == [NSNull null]
|| ([obj respondsToSelector:@selector(length)] && [obj length] == 0)
|| ([obj respondsToSelector:@selector(count)] && [obj count] == 0);
}
// swift-tools-version: 6.1
import PackageDescription
let package = Package(
name: "SwiftFormatPlugin",
products: [
.plugin(name: "SwiftFormatPlugin", targets: ["SwiftFormatPlugin"])
],
targets: [
.plugin(name: "SwiftFormatPlugin", capability: .buildTool)
enum AsyncError: Error {
case finishedWithoutValue
}
extension AnyPublisher {
func async() async throws -> Output {
try await withCheckedThrowingContinuation { continuation in
var cancellable: AnyCancellable?
var finishedWithoutValue = true
cancellable = first()
# Uncrustify 0.59
#
# General options
#
# The type of line endings
newlines = auto # auto/lf/crlf/cr
# The original size of tabs in the input
@tonyarnold
tonyarnold / CompareTools.plist
Created March 6, 2019 22:35
Git Tower & Sublime Merge Integration
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>ApplicationIdentifier</key>
<string>com.sublimemerge</string>
<key>ApplicationName</key>
<string>Sublime Merge</string>
<key>DisplayName</key>
@tonyarnold
tonyarnold / mr-save-patterns.md
Last active October 21, 2023 00:55
Common save patterns for use with MagicalRecord

Common Save Patterns

Standard background save

Assuming that you don't care which NSManagedObjectContext is used, and you just want to make some changes and save them in the background, use the following method. 90% of the time, this is what you'll want.

NSManagedObjectSubclass *myObject = [NSManagedObjectSubclass MR_findFirst];

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
@tonyarnold
tonyarnold / Array+NSArrayAppend.swift
Created July 6, 2014 05:10
Originally proposed and provided by Rob Rix allows you to append values from an NSArray to a Swift array, so long as they match the Swift array's expected element type.
import Foundation
@assignment func += <T:AnyObject> (inout array: T[], cocoaArray: NSArray) {
array.extend(
map(cocoaArray) {
$0 as T
}
)
}
@tonyarnold
tonyarnold / NSObject+BidirectionalAssign.swift
Created September 11, 2020 05:52
Experiment to implement bidirectional assignment of values using Combine/KVO publishers
import Combine
import Foundation
extension NSObjectProtocol where Self: NSObject {
/// Assigns each unique element assigned to the key paths specified to the inverse object.
func bidirectionallyAssign<Value: Equatable, B: NSObject>(
from firstKeyPath: ReferenceWritableKeyPath<Self, Value>,
to secondKeyPath: ReferenceWritableKeyPath<B, Value>,
on otherObject: B
) -> [AnyCancellable] {
@tonyarnold
tonyarnold / .gitconfig
Created October 18, 2012 21:00
Shows how I generate my markdown release notes using git commits
[alias]
co = checkout
tagsbydate = for-each-ref --sort=-taggerdate --format='%(refname:short)' refs/tags
previoustag = !sh -c 'git tagsbydate --count 2 | cut -f2 | sed -n 2p'
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
markdownlog = log --color --pretty=format:'* %s `%Cred%h%Creset` - %C(bold blue)[%an](mailto:%ae)%Creset' --abbrev-commit --dense --no-merges --reverse
releasenotes = !sh -c 'git markdownlog ...`git previoustag`'
@tonyarnold
tonyarnold / UIKitCatchupToAppKit.swift
Last active July 16, 2021 16:10
Bring some of AppKit's strongly typed names and identifiers to UIKit
import UIKit
public extension UIStoryboard {
public struct SceneDescriptor {
public let name: UIStoryboard.Name
public let identifier: UIStoryboard.SceneIdentifier
public init(name: UIStoryboard.Name, identifier: UIStoryboard.SceneIdentifier) {
self.name = name