Skip to content

Instantly share code, notes, and snippets.

View soheilbm's full-sized avatar
🐢
I may be slow to respond.

Soheil soheilbm

🐢
I may be slow to respond.
View GitHub Profile
@zrzka
zrzka / ContentView.swift
Created May 19, 2020 10:15
TrackPadView with touches
import SwiftUI
import AppKit
protocol AppKitTouchesViewDelegate: AnyObject {
// Provides `.touching` touches only.
func touchesView(_ view: AppKitTouchesView, didUpdateTouchingTouches touches: Set<NSTouch>)
}
final class AppKitTouchesView: NSView {
weak var delegate: AppKitTouchesViewDelegate?
@SpectralDragon
SpectralDragon / PreviewContextMenu.swift
Created April 8, 2020 19:22
Simple way to implement preview context menu for SwiftUI
//
// ContentView.swift
// PreviewSwiftUI
//
// Created by v.prusakov on 4/8/20.
// Copyright © 2020 v.prusakov. All rights reserved.
//
import SwiftUI
@hmchen
hmchen / xcode.md
Created September 27, 2017 20:54
Xcode Tips

// Use an older version of Xcode to build on a new device. // Example use Xcode 8 to build on a device running iOS 11

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/11.* \ /Applications/Xcode8.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/

@NikhilManapure
NikhilManapure / Gif.swift
Last active October 29, 2023 07:31
Create Gif from array of UIImages in Swift 3
import Foundation
import UIKit
import ImageIO
import MobileCoreServices
extension UIImage {
static func animatedGif(from images: [UIImage]) {
let fileProperties: CFDictionary = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]] as CFDictionary
let frameProperties: CFDictionary = [kCGImagePropertyGIFDictionary as String: [(kCGImagePropertyGIFDelayTime as String): 1.0]] as CFDictionary
@regexident
regexident / AnyDiffable.swift
Created March 17, 2017 10:26 — forked from ollieatkinson/AnyDiffable.swift
Implementation of Paul Heckel's Diff Algorithm in Swift 3
public protocol Diffable: Hashable {
var primaryKeyValue: String { get }
}
public struct AnyDiffable: Diffable {
private let _primaryKeyValue: () -> String
@bleft
bleft / Data+Extension.swift
Created December 14, 2016 13:19
get md5 hash from Data in swift
extension Data {
var md5 : String {
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
_ = self.withUnsafeBytes { bytes in
CC_MD5(bytes, CC_LONG(self.count), &digest)
}
var digestHex = ""
for index in 0..<Int(CC_MD5_DIGEST_LENGTH) {
digestHex += String(format: "%02x", digest[index])
}
@minhwang
minhwang / requestGET.swift
Created November 8, 2016 10:20
How to write code to request GET data
func requestGET(stringURL url:String) -> URLSessionDataTask? {
var task: URLSessionDataTask? = nil
guard let url: URL = URL(string: url) else {
print("URL is invalid..!!")
return task
}
let urlSession = URLSession(configuration: URLSessionConfiguration.default)
@stinger
stinger / Swift3DataTaskDelegate.swift
Last active March 25, 2023 22:12
Swift 3: URLSessionDelegate
//: # Swift 3: URLSessionDelegate
//: The following example shows how to use `OperationQueue` to queue the network requests. This is useful in many ways (for delaying queued requests when the networking goes down for example)
import Foundation
import PlaygroundSupport
class Requester:NSObject {
let opQueue = OperationQueue()
var response:URLResponse?
@joemasilotti
joemasilotti / UI Testing - Mocking Network Data
Last active January 18, 2024 03:35
Xcode UI Testing - How to mock network data
.
@kristopherjohnson
kristopherjohnson / testTaskOutputPipe.swift
Created January 12, 2016 23:00
Demonstrate launching an `NSTask` and asynchronously reading its output.
import Cocoa
/// Demonstrate launching an `NSTask` and asynchronously reading its output.
///
/// Credit: <http://stackoverflow.com/a/23938137/1175>
func testTaskOutputPipe() {
let task = NSTask()
task.launchPath = "/bin/ls"
task.arguments = ["-l", "/Applications"]