Skip to content

Instantly share code, notes, and snippets.

View StanislavK's full-sized avatar
🚜
Working

StanislavK StanislavK

🚜
Working
View GitHub Profile
@maail
maail / Separator Insets to Zero iOS8 Swift
Created September 30, 2014 12:03
Set UITableViews Separator Insets to Zero in iOS8
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if(self.tableView.respondsToSelector(Selector("setSeparatorInset:"))){
self.tableView.separatorInset = UIEdgeInsetsZero
}
if(self.tableView.respondsToSelector(Selector("setLayoutMargins:"))){
self.tableView.layoutMargins = UIEdgeInsetsZero
}
if(cell.respondsToSelector(Selector("setLayoutMargins:"))){
@raven
raven / ViewController.swift
Last active May 11, 2017 20:12
rdar://30739102
//
// ViewController.swift
// AttributedString
//
// Created by Peter Goldsmith on 27/02/2017.
//
import UIKit
class ViewController: UIViewController {
@steipete
steipete / DevelopmentEnviromentDetector.m
Last active October 30, 2019 03:49
Detect if you're currently running a development version or an App Store/Ad Hoc version.
static BOOL PSPDFIsDevelopmentBuild(void) {
#if TARGET_IPHONE_SIMULATOR
return YES;
#else
static BOOL isDevelopment = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// There is no provisioning profile in AppStore Apps.
NSData *data = [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]];
if (data) {
@JohnSundell
JohnSundell / Perform.swift
Last active December 21, 2019 14:43
A function that enables you to easily wrap throwing APIs, to provide a custom error
/**
* Perform a throwing expression, and throw a custom error in case the expression threw
*
* - parameter expression: The expression to execute
* - parameter error: The custom error to throw instead of the expression's error
* - throws: The given error
* - returns: The return value of the given expression
*/
func perform<T>(_ expression: @autoclosure () throws -> T, orThrow errorExpression: @autoclosure () -> Error) throws -> T {
do {
@discardableResult
public func with<T>(_ value: T, _ builder: (T) -> Void) -> T {
builder(value)
return value
}
@discardableResult
public func with<T>(_ value: T, _ builder: (T) throws -> Void ) rethrows -> T {
try builder(value)
return value
//:
//: UserDefaultable.swift
//:
//: Created by Andyy Hope on 18/08/2016.
//: Twitter: @andyyhope
//: Medium: Andyy Hope, https://medium.com/@AndyyHope
import Foundation
// MARK: - Key Namespaceable
@christianselig
christianselig / UITableViewHeaderFooterView+Swizzle.swift
Created October 1, 2021 20:11
Swizzle UITableViewHeaderFooterView to make header color customizable. Done in willMoveToWindow (once) because it should occur right before visible.
extension UITableViewHeaderFooterView {
private static var hasFiredOnceKey = "apollo_hasFiredOnceKey"
static func apollo_swizzle() {
// To be called in AppDelegate.didFinishLaunching
let originalSelector = #selector(willMove(toWindow:))
let swizzledSelector = #selector(apollo_willMove(toWindow:))
guard let originalMethod = class_getInstanceMethod(self, originalSelector), let swizzledMethod = class_getInstanceMethod(self, swizzledSelector) else {
assertionFailure("Original method or swizzled method is unavailable")
@YusukeHosonuma
YusukeHosonuma / UIViewController.swift
Last active December 9, 2021 12:30
Capture UITableView full content.
//
// ViewController.swift
// UIViewCapture
//
// Created by Yusuke on 11/7/16.
// Copyright © 2016 Yusuke. All rights reserved.
//
import UIKit
@n-studio
n-studio / DataUsage.swift
Last active July 12, 2022 00:21
Get data usage with swift
#include <ifaddrs.h>
// http://stackoverflow.com/questions/25626117/how-to-get-ip-address-in-swift
func getIFAddresses() -> [String] {
var addresses = [String]()
// Get list of all interfaces on the local machine:
var ifaddr : UnsafeMutablePointer<ifaddrs> = nil
if getifaddrs(&ifaddr) == 0 {
@phranck
phranck / PlatformVisibility.swift
Last active November 13, 2022 22:40
A Swift view modifier to handle visibility of views for specific platforms
import SwiftUI
public struct Platform: OptionSet {
public var rawValue: UInt8
public static let iOS = Platform(rawValue: 1 << 0)
public static let macOS = Platform(rawValue: 1 << 1)
public static let tvOS = Platform(rawValue: 1 << 2)
public static let watchOS = Platform(rawValue: 1 << 3)
public static let all: Platform = [.iOS, .macOS, .tvOS, .watchOS]