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
@gatherheart
gatherheart / swift-frontend.txt
Created July 18, 2023 01:50 — forked from palaniraja/swift-frontend.txt
Swift frontend usage reference
OVERVIEW: Swift frontend
USAGE: swift-frontend -frontend
MODES:
-compile-module-from-interface
Treat the (single) input as a swiftinterface and produce a module
-dump-ast Parse and type-check input file(s) and dump AST(s)
-dump-interface-hash Parse input file(s) and dump interface token hash(es)
-dump-parse Parse input file(s) and dump AST(s)
@gatherheart
gatherheart / runCommand.swift
Created April 1, 2023 16:17 — forked from dduan/runCommand.swift
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
@gatherheart
gatherheart / readme.md
Created January 4, 2023 09:56 — forked from bgromov/readme.md
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:
@gatherheart
gatherheart / git-mv-with-history
Created December 6, 2022 04:34 — forked from emiller/git-mv-with-history
git utility to move/rename file or folder and retain history with it.
#!/bin/bash
#
# git-mv-with-history -- move/rename file or folder, with history.
#
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
#
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.
@gatherheart
gatherheart / LocalCommunicationNotification.swift
Created November 15, 2022 02:33 — forked from Dexwell/LocalCommunicationNotification.swift
iOS 15 Local Communication Notification
var content = UNMutableNotificationContent()
content.title = "Title"
content.subtitle = "Subtitle"
content.body = "Text"
content.sound = nil
content.categoryIdentifier = "categoryName"
var personNameComponents = PersonNameComponents()
personNameComponents.nickname = "Sender Name"
@gatherheart
gatherheart / UILabelCountLines.swift
Created February 25, 2022 04:26 — forked from fuxingloh/UILabelCountLines.swift
iOS Swift: How to check if UILabel is truncated? Calculate number of lines for UILabel
func countLabelLines(label: UILabel) -> Int {
// Call self.layoutIfNeeded() if your view uses auto layout
let myText = label.text! as NSString
let rect = CGSize(width: label.bounds.width, height: CGFloat.greatestFiniteMagnitude)
let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: label.font], context: nil)
return Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight))
}
@gatherheart
gatherheart / implementationWithBlock.swift
Created January 18, 2022 16:39 — forked from neonichu/implementationWithBlock.swift
How to use imp_implementationWithBlock in Swift
import Foundation
import ObjectiveC.runtime
let myString = "foobar" as NSString
println(myString.description)
let myBlock : @objc_block (AnyObject!) -> String = { (sself : AnyObject!) -> (String) in
"✋"
}
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
@gatherheart
gatherheart / Image Caching OpenSource.md
Created April 21, 2021 08:55 — forked from linearhw/Image Caching OpenSource.md
이미지 캐싱 오픈소스 라이브러리에 대한 요약/정리

성능 비교하기

  • 테스트앱
  • 낮은 해상도 = 사진 크기: 10 ~ 50KB
  • 중간 해상도 = 사진 크기: 100 ~ 500KB + 5MB
  • 높은 해상도 = 사진 크기: 10 ~ 50MB
  • 기본 설정 = 설정: 메모리 100MB 디스크 150MB
  • 리사이즈 = (화면 너비 / 3)^2. iPhone 8+ 기준으로 414 pixel.

리사이즈 없이 테스트

@gatherheart
gatherheart / graphql-args-passing.md
Created November 12, 2020 09:05 — forked from loganpowell/graphql-args-passing.md
GraphQL Passing Arguments (parent, args, context, info)