Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
benbahrenburg / UIImageToDataIO.swift
Created March 5, 2017 23:55
Using ImageIO and Swift to convert a UIImage to Data
func UIImageToDataIO(image: UIImage, compressionRatio: CGFloat, orientation: Int = 1) -> Data? {
return autoreleasepool(invoking: { () -> Data in
let data = NSMutableData()
let options: NSDictionary = [
kCGImagePropertyOrientation: orientation,
kCGImagePropertyHasAlpha: true,
kCGImageDestinationLossyCompressionQuality: compressionRatio
]
let imageDestinationRef = CGImageDestinationCreateWithData(data as CFMutableData, kUTTypeJPEG, 1, nil)!
@leilee
leilee / Install iOS Simulators in Xcode Manually.md
Last active April 17, 2024 07:03
Install iOS Simulators in Xcode Manually
  • Open Xcode -> Preferences -> Components.
  • Open the Console App, clear the console.
  • Go back to the Xcode preferences. Start the simulator download, then cancel it.
  • Now in the Console, you will see something about the cancellation with the download URL.
  • Copy the URL from the Console, download it.
  • Copy this file to ~/Library/Caches/com.apple.dt.Xcode/Downloads.
    • If Downloads did not exist, create a new Downloads directory.
    • If Downloads exists, remove all *.dvtdownloadableindex files under it.
  • Open Xcode -> Preferences -> Components, start the simulator download again, it should find the file you downloaded and install it.
@bardonadam
bardonadam / Form.swift
Created December 12, 2019 08:11
Custom decode with SomeKindOfBool
struct Form: Codable, Equatable {
let id: Int
let type: FType
let name: String
let code: String
let hasScreenshot: Bool
let total: Int
let totalUnique: Int
let opened: Int
@SomeKindOfBool var active: Bool