Skip to content

Instantly share code, notes, and snippets.

View bartleby's full-sized avatar
🦄
One More Time

Aleksei Artemev bartleby

🦄
One More Time
View GitHub Profile
import SwiftUI
extension CGPoint {
static func *(lhs: Self, rhs: CGFloat) -> Self {
.init(x: lhs.x * rhs, y: lhs.y * rhs)
}
}
// Idea: https://www.framer.com/showcase/project/lo2Qka8jtPXrjzZaPZdB/
@WoonHaKim
WoonHaKim / example.ios.yml
Last active July 17, 2023 03:43
GitHub Action iOS build workflow example
name: Example iOS Build
on:
push:
branches:
- development
jobs:
build-ios:
runs-on: macos-latest
@unnamedd
unnamedd / MacEditorTextView.swift
Last active April 16, 2024 10:18
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI

Self в Swift и Objective-C

Дисклеймер: речь идёт об однопоточном коде, оставим ужасы параллельного исполнения за скобками. Также не рассматривается возможность overrelease.

Objective-C

Объект точно не ритейнится на время выполнения его метода, пруфы:

@ha1f
ha1f / CIFilter+Extension.swift
Last active February 20, 2024 08:14
CIFilter+Extension.swift
//
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
//
import Foundation
import CoreImage
import AVFoundation
extension CIFilter {
@ilyapuchka
ilyapuchka / StickyLayout.swift
Last active February 25, 2024 18:43
Really sticky collection view layout
// The issue with sectionHeadersPinToVisibleBounds and sectionFootersPinToVisibleBounds is that they do not pin
// first header and last footer when bouncing. This layout subclass fixes that.
class StickyLayout: UICollectionViewFlowLayout {
override init() {
super.init()
self.sectionFootersPinToVisibleBounds = true
self.sectionHeadersPinToVisibleBounds = true
}
@JadenGeller
JadenGeller / Cluster.swift
Created March 13, 2017 01:27
Class Cluster
class Number /* class cluser */ {
class Int8: Number {
var value: Swift.Int8
init(_ value: Swift.Int8) { self.value = value }
}
class Int: Number {
var value: Swift.Int
init(_ value: Swift.Int) { self.value = value }
}
open class LinearScale {
var domain: [CGFloat]
var range: [CGFloat]
public init(domain: [CGFloat] = [0, 1], range: [CGFloat] = [0, 1]) {
self.domain = domain
self.range = range
}
@pkuecuekyan
pkuecuekyan / WKWebViewSizeToFit.swift
Last active March 12, 2024 11:37
Adjust height of WKWebView frame based on scrollHeight of the webView's content
// Since the WKWebView has no sizeToFit() method, increase the frame height of the webView to
// match the height of the content's scrollHeight
//
// The WKWebView's `navigationDelegate` property needs to be set for the delegate method to be called
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
if webView.isLoading == false {
webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { [weak self] (result, error) in
if let height = result as? CGFloat {
@cmoulton
cmoulton / Custom HTTP Headers with Swift and Alamofire.swift
Last active July 15, 2022 12:37
Custom HTTP Headers with Swift 3 or 4 and Alamofire 4.0-4.7: See https://grokswift.com/custom-headers-alamofire4-swift3/ for explanations
// MARK: - Adding a header to a single request
func doRequestWithHeaders1() {
let headers: HTTPHeaders = [
"X-Mashape-Key": MY_API_KEY,
"Accept": "application/json"
]
Alamofire.request("https://mashape-community-urban-dictionary.p.mashape.com/define?term=smh", headers: headers)
.responseJSON { response in
debugPrint(response)