Skip to content

Instantly share code, notes, and snippets.

View StanislavK's full-sized avatar
🚜
Working

StanislavK StanislavK

🚜
Working
View GitHub Profile
@Gurdeep0602
Gurdeep0602 / AppStoryboard.swift
Last active April 2, 2024 09:54
AppStoryboard enumeration
//
// AppStoryboards.swift
// AppStoryboards
//
// Created by Gurdeep on 15/12/16.
// Copyright © 2016 Gurdeep. All rights reserved.
//
import Foundation
import UIKit
@gonzalezreal
gonzalezreal / ios-cell-registration-swift.md
Last active March 13, 2024 15:18
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@mattt
mattt / UIViewControllerPreview.swift
Last active January 8, 2024 23:09
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
@steipete
steipete / ios-xcode-device-support.sh
Last active December 12, 2023 03:36
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
@finestructure
finestructure / Charting.swift
Last active October 23, 2023 20:22
Swift playground example to create charts with a PDF export button
import SwiftUI
import Charts
import PlaygroundSupport
let spiData: [(package: String, fileCount: Int, mbSize: Int)] = [
(package: "swift-markdown-ui", fileCount: 3796, mbSize: 44),
(package: "Microya", fileCount: 414, mbSize: 4),
(package: "swift-url-routing", fileCount: 9430, mbSize: 101),

Greetings, NSHipsters!

As we prepare to increment our NSDateComponents -year by 1, it's time once again for NSHipster end-of-the-year Reader Submissions! Last year, we got some mind-blowing tips and tricks. With the release of iOS 7 & Mavericks, and a year's worth of new developments in the Objective-C ecosystem, there should be a ton of new stuff to write up for this year.

Submit your favorite piece of Objective-C trivia, framework arcana, hidden Xcode feature, or anything else you think is cool, and you could have it featured in the year-end blowout article. Just comment on this gist below!

Here are a few examples of the kind of things I'd like to see:

  • Using NSStringFromSelector(@selector()) as a safer way to do KVC / KVO / NSCoding.
  • Panic's [rather surprising discovery about the internals of the Lightning Digital AV Adapter](http://www.panic.com/blog/the-lightning-di
@simme
simme / debounce-throttle.swift
Created December 20, 2016 10:04
Swift 3 debounce & throttle
//
// debounce-throttle.swift
//
// Created by Simon Ljungberg on 19/12/16.
// License: MIT
//
import Foundation
extension TimeInterval {
@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]
@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 {
@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