Skip to content

Instantly share code, notes, and snippets.

@hishma
hishma / Bundle+Hishma.swift
Created January 16, 2019 23:59
Provides convenience accesors to some info dictionary keys
/// Provides convenience accesors to some info dictionary keys
extension Bundle {
var identifier: String? {
return string(forInfoDictionaryKey: "CFBundleIdentifier")
}
var displayName: String? {
return string(forInfoDictionaryKey: "CFBundleDisplayName")
}
@hishma
hishma / CLLocation+Encodable.swift
Created January 16, 2019 23:57
CoreLocation and Codable
extension CLLocation: Encodable {
public enum CodingKeys: String, CodingKey {
case latitude
case longitude
case altitude
case horizontalAccuracy
case verticalAccuracy
case speed
case course
case timestamp
@hishma
hishma / CLLocation+Hishma.swift
Created January 16, 2019 23:54
Handy CorelLocation extension. Or so I think.
extension CLLocation {
/// Compass bearing from a known location
///
/// Shamelessly stolenfrom // https://stackoverflow.com/questions/26998029/calculating-bearing-between-two-cllocation-points-in-swift
///
/// - Parameter location: The `CLocation` to calculate the bearing from.
/// - Returns: The `CLLocationDirection` representing the compass bearing.
func bearing(from location: CLLocation) -> CLLocationDirection {
func degreesToRadians(degrees: CLLocationDirection) -> CLLocationDirection { return degrees * .pi / 180.0 }
@hishma
hishma / String+Hishma.swift
Last active January 23, 2019 22:41
String extensions to make my life more convenient. When I remember them…
extension String {
/// Replace all instances of characters in a character set.
///
/// - Parameters:
/// - characterSet: The `CharacterSet` containing the characters to replace in the string.
/// - replacementString: The `String` to replace the matched characters with.
/// - Returns: A new `String` with all characters in the character set replaced by the replacement string.
func replacingCharacters(in characterSet: CharacterSet, with replacementString: String = "") -> String {
return self.components(separatedBy: characterSet).joined(separator: replacementString)
}
@hishma
hishma / NSPersonNameComponents.swift
Created May 5, 2016 14:02
Swift extension to NSPersonNameComponents for Prince & friends.
//
// NSPersonNameComponents.swift
//
import Foundation
extension NSPersonNameComponents {
// Because the web is generally xenophobic…
var xenophobicName: (firstName: String, lastName: String)? {
@hishma
hishma / logPretty.swift
Created December 17, 2015 00:08
Debug like a caveman in swift
func logPretty(message: String? = nil, file: String = __FILE__, line: UInt = __LINE__, function: StaticString = __FUNCTION__) {
var pretty = "\((file as NSString).lastPathComponent)(\(line)) : \(function)"
if let message = message where !message.isEmpty {
pretty += " ☞ \(message)"
}
print(pretty)
}
@hishma
hishma / versionInSettings.md
Last active May 31, 2022 07:26
Display iOS app version in settings

To display the current version of an iOS app in the settings

  1. Add an entry like this in Settings.bundle/Root.plist
<key>PreferenceSpecifiers</key>
<array>
  <dict>
    <key>Type</key>
 PSTitleValueSpecifier
@hishma
hishma / fix-xcode-docs.md
Last active October 10, 2022 16:10
HowTo Fix Xcode Documentation

Fix for missing documentation indexes and other anomolies in the Xcode documentation viewer. Mine seemed to get all borked up with some beta relaeases. Shamelessly ripped off from this thread.

  1. Quit Xcode
  2. Delete the cache file at ~/Library/Caches/com.apple.dt.Xcode.
  3. Delete the contents of ~/Library/Developer/Shared/Documentation/DocSets/.
  4. Delete the contents of /Applications/Xcode.app/Contents/Developer/Documentation/DocSets/.
  5. Launch Xcode.
  6. Open the Preferences pane, select the Downloads tab, and download the docsets you want to use.
@hishma
hishma / 256-char
Created April 8, 2014 16:39
256 Character String
THIS STRING IS 256 CHARACTERS xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@hishma
hishma / smoked_salmon_chowder.md
Last active November 16, 2020 21:01
Smoked Salmon Chowder Recipe

Smoke Salmon Chowder

Bone warming goodness on a cold rainy day.

Ingredients

  • Smoked Salmon (a typical store package seems to work fine)
  • Small container heavy cream
  • Handful of nice small potatoes (red new, yukon gold, whatev)
  • Couple of standard issue carrots