Skip to content

Instantly share code, notes, and snippets.

@mattt
mattt / uiappearance-selector.md
Last active March 19, 2024 12:52
A list of methods and properties conforming to `UIAppearance` as of iOS 12 Beta 3

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep UI_APPEARANCE_SELECTOR ./*     | \
  sed 's/NS_AVAILABLE_IOS(.*)//g'     | \
  sed 's/NS_DEPRECATED_IOS(.*)//g'    | \
  sed 's/API_AVAILABLE(.*)//g'        | \
  sed 's/API_UNAVAILABLE(.*)//g'      | \
 sed 's/UI_APPEARANCE_SELECTOR//g' | \
@mattt
mattt / UIViewControllerPreview.swift
Last active January 8, 2024 23:09
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
@mattt
mattt / main.swift
Last active January 8, 2024 07:48
NaturalLanguage Framework - NLTagger Language Support Matrix
import NaturalLanguage
let languages: [NLLanguage] = [
.amharic, .arabic, .armenian, .bengali, .bulgarian,
.burmese, .catalan, .cherokee, .croatian, .czech,
.danish, .dutch, .english, .finnish, .french,
.georgian, .german, .greek, .gujarati, .hebrew,
.hindi, .hungarian, .icelandic, .indonesian, .italian,
.japanese, .kannada, .khmer, .korean, .lao,
.malay, .malayalam, .marathi, .mongolian, .norwegian,
import Foundation
extension Locale {
func localizedCurrencySymbol(forCurrencyCode currencyCode: String) -> String? {
guard let languageCode = languageCode, let regionCode = regionCode else { return nil }
/*
Each currency can have a symbol ($, £, ¥),
but those symbols may be shared with other currencies.
For example, in Canadian and American locales,
func zalgo(_ string: String, intensity: Int = 5) -> String {
let combiningDiacriticMarks = 0x0300...0x036f
let latinAlphabetUppercase = 0x0041...0x005a
let latinAlphabetLowercase = 0x0061...0x007a
var output: [UnicodeScalar] = []
for scalar in string.unicodeScalars {
output.append(scalar)
guard (latinAlphabetUppercase).contains(numericCast(scalar.value)) ||
(latinAlphabetLowercase).contains(numericCast(scalar.value))
@mattt
mattt / bridge.swift
Last active June 14, 2023 11:47
Example usage of @mxcl's swift-sh
#!/usr/bin/swift sh
import DeckOfPlayingCards // @NSHipster ~> 4.0.0
import PlayingCard
import Cycle // @NSHipster == bb11e28
class Player {
var name: String
var hand: [PlayingCard] = []
@mattt
mattt / registry.bash
Created June 18, 2020 15:44
An example of how Git can be used as a transparent log for a package registry
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
# Returns the SHA-256 checksum of a string or file
function checksum() {
if [ -f "$1" ]; then
shasum -a 256 "$1" | cut -d ' ' -f1
// See: https://devforums.apple.com/message/1000934#1000934
import Foundation
// Logic
operator prefix ¬ {}
@prefix func ¬ (value: Bool) -> Bool {
return !value
}
@mattt
mattt / NSDecimalNumber.swift
Last active April 1, 2023 00:06
NSDecimalNumber Additions for Swift
import Foundation
// MARK: - Comparable
extension NSDecimalNumber: Comparable {}
public func ==(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .OrderedSame
}

Greetings, NSHipsters!

As we prepare to increment our NSDateComponents -year by 1, it's time once again for NSHipster end-of-the-year Reader Submissions! Last year, we got some mind-blowing tips and tricks. With the release of iOS 7 & Mavericks, and a year's worth of new developments in the Objective-C ecosystem, there should be a ton of new stuff to write up for this year.

Submit your favorite piece of Objective-C trivia, framework arcana, hidden Xcode feature, or anything else you think is cool, and you could have it featured in the year-end blowout article. Just comment on this gist below!

Here are a few examples of the kind of things I'd like to see:

  • Using NSStringFromSelector(@selector()) as a safer way to do KVC / KVO / NSCoding.
  • Panic's [rather surprising discovery about the internals of the Lightning Digital AV Adapter](http://www.panic.com/blog/the-lightning-di