Skip to content

Instantly share code, notes, and snippets.

View gatherheart's full-sized avatar
๐Ÿค—
Always Gather Heart

Milkybean gatherheart

๐Ÿค—
Always Gather Heart
View GitHub Profile
@bgromov
bgromov / readme.md
Last active September 30, 2023 15:35
Compiling Swift framework with mixed-in Objective-C code

Problem

You can't use bridging headers within a framework.

Solution 1 (umbrella header):

Xcode will automatically create umbrella header for you Cocoa Framework project. That will be the file named <FrameworkName>.h in the <FrameworkName> group/folder (where the rest of your sources are).

  1. To include the required Obj-C header you need to set it as Public: select it in the project explorer (left pane) and change the property Target Membership (leftโ€”Inspectorsโ€”pane) from Project to Public.
  2. Open umbrella header (<FrameworkName>.h) and import the required header as:
@CraftingGamerTom
CraftingGamerTom / Learn Git Branching.md
Last active May 15, 2025 23:56
learn-git-branching-solution learn-git-branching-main learn-git-branching-remote learn git branching solution learn git branching main learn git branching remote

Learning Git Branching

Please do not continue if you have not learned the content covered in these assignments. It is important to learn the material. However if, like me, you find yourself needing to complete arbitrary tasks for classes you are capable of testing out of - but its not offered. Please continue...

README: To use this quickly, copy and paste the entire block of code in the 'console' using CTRL-V. They have been written so you do not need to copy each line, one-by-one

Main

1.1 Introduction to Git Commits

@yusuke024
yusuke024 / ViewController.swift
Created November 16, 2018 03:15
Recording video with AVAssetWriter
import UIKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .notDetermined:
@loganpowell
loganpowell / graphql-args-passing.md
Last active December 25, 2024 23:14
GraphQL Passing Arguments (parent, args, context, info)
class ReadValue {
private var thread : Thread? = nil
init(with handler: @escaping (String) -> ()) {
thread = Thread(block: {
while(true) {
let value = readLine() ?? ""
handler(value)
}
})
thread?.start()
import Foundation
class ReadValue {
var successClosure : ((String)->())? = nil
var value : String = "" {
didSet {
if let closure = successClosure {
closure(value)
}
}
}
@cjnevin
cjnevin / UIView+Accessibility.swift
Last active June 6, 2022 08:31
Automatically add Accessibility Labels/Identifiers to all components that extend UIView
import UIKit
private func isExcluded(_ kind: AnyClass) -> Bool {
let name = String(describing: kind)
return (name.count > 2 && name.prefix(2) == "UI") ||
(name.count > 3 && name.prefix(3) == "_UI")
}
extension UIControl {
override open var accessibilityIdentifier: String? {
@godrm
godrm / swift_api_guideline.md
Last active February 20, 2025 11:30
์Šค์œ„ํ”„ํŠธ API ๊ฐ€์ด๋“œ๋ผ์ธ

1. ์Šคํƒ€์ผ/๋ฌธ๋ฒ• ๋ฆฌ๋ทฐ

1-1 ์Šค์œ„ํ”„ํŠธ API ๋””์ž์ธ ๊ฐ€์ด๋“œ๋ผ์ธ

https://swift.org/documentation/api-design-guidelines/

  • ์‚ฌ์šฉํ•  ๋•Œ ๊ธฐ์ค€์œผ๋กœ ๋ช…ํ™•ํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๋Š” ๊ฒŒ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์ง€ํ–ฅ์ ์ด๋‹ค. ๋ฉ”์†Œ๋“œ๋‚˜ ํ”„๋กœํผํ‹ฐ ๊ฐ™์€ ๊ฐœ๋ฐœ ์š”์†Œ๋Š” ํ•œ ๋ฒˆ๋งŒ ์„ ์–ธํ•˜๊ณ  ๋ฐ˜๋ณต์ ์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค. API๋ฅผ ๋งŒ๋“ค ๋•Œ๋Š” ์‚ฌ์šฉํ•˜๊ธฐ ๋ช…ํ™•ํ•˜๊ณ  ํŽธํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค. ์„ค๊ณ„๋ฅผ ๊ฒ€์ฆํ•  ๋•Œ ์„ ์–ธ ๋ถ€๋ถ„์„ ์ฝ๋Š” ๊ฒƒ๋งŒ์œผ๋กœ๋Š” ๋ถ€์กฑํ•˜๋‹ค. ๊ทธ ๋Œ€์‹  ์‚ฌ์šฉํ•˜๋Š” ์ƒํ™ฉ์—์„œ ๋งฅ๋ฝ์— ๋งž๊ณ  ๋ช…ํ™•ํ•œ ์ง€ ๋Š˜ ๊ณ ๋ คํ•ด์•ผ ํ•œ๋‹ค.

  • ๋ช…ํ™•ํ•œ ํ‘œํ˜„์ด ์••์ถ•ํ•œ ๊ฐ„๊ฒฐ์„ฑ๋ณด๋‹ค ๋” ์ค‘์š”ํ•˜๋‹ค. ์Šค์œ„ํ”„ํŠธ ์ฝ”๋“œ๋Š” ์••์ถ•ํ•ด์„œ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ๋‹จ์ง€ ๊ธ€์ž์ˆ˜๋ฅผ ์ค„์—ฌ์„œ ๊ฐ€์žฅ ์งง์€ ์ฝ”๋“œ๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒŒ ๋ชฉํ‘œ๋Š” ์•„๋‹ˆ๋‹ค. ์Šค์œ„ํ”„ํŠธ ์ฝ”๋“œ์˜ ๊ฐ„๊ฒฐ์„ฑ์€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋ฐ˜๋ณต์ ์œผ๋กœ ์žฌ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ(boilerplate)๋ฅผ ์ค„์ด๋Š” ๊ธฐ๋Šฅ๊ณผ ๊ฐ•ํ•œ ํƒ€์ž… ์‹œ์Šคํ…œ์˜ ๋ถ€์ˆ˜ํšจ๊ณผ๋กœ ๋“œ๋Ÿฌ๋‚  ๋ฟ์ด๋‹ค.

@dduan
dduan / runCommand.swift
Last active June 18, 2025 21:34
How to fork()+execv() in Swift
import Foundation
func withCStrings(_ strings: [String], scoped: ([UnsafeMutablePointer<CChar>?]) throws -> Void) rethrows {
let cStrings = strings.map { strdup($0) }
try scoped(cStrings + [nil])
cStrings.forEach { free($0) }
}
enum RunCommandError: Error {
case WaitPIDError
@misbell
misbell / gist:fa7ecd562a9b0d9c1237eed5e1a6d89e
Created October 16, 2016 01:43
example Swift 3 withMemoryRebound
so A and B are structurally identical
C reverses the order of the 8 and 32 bit Ints
and D substitutes a string for the Int8
then I try to read aaaaโ€™s bits using B C and D overlays ๐Ÿ˜Š
C is printing the 8 bits of the A integer j and then the first 8 bits of integer k but somehow that still works out to one
when I hit D it doesnโ€™t find a string so prints a blank
but the important point is: it doesnโ€™t check anything, and doesnโ€™t crash