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 July 10, 2024 18:22
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 June 8, 2023 17:51
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 July 15, 2024 13:21
스위프트 API 가이드라인

1. 스타일/문법 리뷰

1-1 스위프트 API 디자인 가이드라인

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

  • 사용할 때 기준으로 명확하게 작성하는 게 가장 중요한 지향점이다. 메소드나 프로퍼티 같은 개발 요소는 한 번만 선언하고 반복적으로 사용한다. API를 만들 때는 사용하기 명확하고 편하게 만들어야 한다. 설계를 검증할 때 선언 부분을 읽는 것만으로는 부족하다. 그 대신 사용하는 상황에서 맥락에 맞고 명확한 지 늘 고려해야 한다.

  • 명확한 표현이 압축한 간결성보다 더 중요하다. 스위프트 코드는 압축해서 간결하게 작성할 수 있지만, 단지 글자수를 줄여서 가장 짧은 코드를 만드는 게 목표는 아니다. 스위프트 코드의 간결성은 자연스럽게 반복적으로 재사용하는 코드(boilerplate)를 줄이는 기능과 강한 타입 시스템의 부수효과로 드러날 뿐이다.

@dduan
dduan / runCommand.swift
Last active May 5, 2024 12:55
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