Skip to content

Instantly share code, notes, and snippets.

@ollieatkinson
ollieatkinson / SVG.swift
Last active February 23, 2024 04:59
Utilise the private CoreSVG framework in Swift
import Darwin
import Foundation
import UIKit
// https://github.com/xybp888/iOS-SDKs/blob/master/iPhoneOS17.1.sdk/System/Library/PrivateFrameworks/CoreSVG.framework/CoreSVG.tbd
// https://developer.limneos.net/index.php?ios=17.1&framework=UIKitCore.framework&header=UIImage.h
@objc
class CGSVGDocument: NSObject { }
@lengocgiang
lengocgiang / animation.swift
Created December 3, 2017 09:52
addSubview and removeFromSuperview animation in Swift 4.0
# addSubview
UIView.transition(with: self.view, duration: 0.25, options: [.transitionCrossDissolve], animations: {
self.view.addSubview(view)
}, completion: nil)
# removeFromSuperview
UIView.transition(with: self.view, duration: 0.25, options: [.transitionCrossDissolve], animations: {
subview.removeFromSuperview()
}, completion: nil)
@bittz
bittz / QuadPageControl.swift
Last active February 12, 2023 16:42
UIPageControl with square dots having custom size (hack).
import UIKit
class QuadPageControl: UIPageControl {
override func layoutSubviews() {
super.layoutSubviews()
guard !subviews.isEmpty else { return }
let spacing: CGFloat = 3
//
// UIBarButtonItem+Badge.swift
// PiGuardMobile
//
// Created by Stefano Vettor on 12/04/16.
// Copyright © 2016 Stefano Vettor. All rights reserved.
//
import UIKit
@justAnotherDev
justAnotherDev / GetJSONValue.swift
Created February 3, 2016 10:26
Swift extensions for retrieving values from a JSON response
extension Dictionary where Key: StringLiteralConvertible, Value:AnyObject {
subscript(keysAndIndexes: AnyObject ...) -> AnyObject? {
guard let jsonObject = self as? AnyObject else { fatalError("\(self) is not a json dictionary") }
return _extractValueFrom(keysAndIndexes, from: jsonObject)
}
}
extension Array where Element:AnyObject {
subscript(keysAndIndexes: AnyObject ...) -> AnyObject? {
return _extractValueFrom(keysAndIndexes, from: self)
@justAnotherDev
justAnotherDev / SwiftExceptionHandler.h
Created January 31, 2016 10:30
Swift Exception Handler - tryBlock
NS_INLINE NSException * _Nullable tryBlock(void(^_Nonnull tryBlock)(void)) {
@try {
tryBlock();
}
@catch (NSException *exception) {
return exception;
}
return nil;
}
@juliengdt
juliengdt / SwiftIntegerChecker.swift
Created August 26, 2015 07:48
To check if a number is between a range in Swift
// To check if a number is between a range, don't do
if number >=0 && number <= 100 {
}
// Use range and news operators instead :
if 0...100 ~= number {
}
@c9iim
c9iim / AXUIElement_in_Swift_pert2.swift
Last active December 16, 2017 23:40
AXUIElement in Swift pert2
import Cocoa
extension NSWorkspace {
class func frontmostApp() -> NSRunningApplication? {
return self.sharedWorkspace().frontmostApplication
}
class func runningApp(bundleIdentifier:NSString) -> NSRunningApplication? {
let runningApplications = NSWorkspace.sharedWorkspace().runningApplications
return runningApplications.filter({$0.bundleIdentifier == bundleIdentifier}).first
}
@c9iim
c9iim / AXUIElement_in_Swift.swift
Last active May 9, 2023 07:45
AXUIElement in Swift
import Cocoa
protocol AXUIProtocol {
func AXUIWindowArray(processIdentifier pid:pid_t) -> [AXUIElement]
func AXUIWindowArray(bundleIdentifier bid:NSString) -> [AXUIElement]
}
extension AXUIProtocol {
func AXUIWindowArray(processIdentifier pid:pid_t) -> [AXUIElement] {
let windowList : UnsafeMutablePointer<AnyObject?> = UnsafeMutablePointer<AnyObject?>.alloc(1)
@edwardmp
edwardmp / gist:a0ffb3ace02ce4392b26
Created June 13, 2015 15:58
Working example of accepting self-signed SSL certificate in Swift
import UIKit
import Foundation
class ViewController: UIViewController, NSURLSessionDelegate {
override func viewDidLoad() {
super.viewDidLoad()
httpGet(NSMutableURLRequest(URL: NSURL(string: "https://example.com")!))
}