Skip to content

Instantly share code, notes, and snippets.

[alias]
vacuum = "!f () { git checkout $1; git branch --merged|egrep -v '\\*|develop|main'|xargs git branch -d; git fetch --prune; };f"
@hira22
hira22 / NumberArray.playground
Created April 13, 2023 07:42
map と reduce の説明
import Foundation
// MARK: 1. 1〜10の配列を用意する
print(
(1...10).map{ $0 }
)
// MARK: 2. 1〜10の合計を求める forEach
var result: Int = 0
(1...10).map{ $0 }.forEach { (value: Int) in
@hira22
hira22 / ActorSample.playground
Created April 13, 2023 07:23
Actor のサンプル
import _Concurrency
// MARK: Class
print("------------------ CLASS ------------------------")
// class だと順番がぐちゃぐちゃになることがある 1 -> 8 まで順番に出力されない(データ競合)
class ClassCounter {
static var shared = ClassCounter()
private init() {}
//
// LineDivider.swift
//
//
// Created by hira22 on 2021/08/13.
//
import SwiftUI
struct LineDivider: View {
@hira22
hira22 / SwiftUITableViewCell.swift
Created July 29, 2021 05:55
SwiftUIView を UITableView で使う。
import SwiftUI
import UIKit
class SwiftUIViewInUITableViewCell: UITableViewCell {
static var reuseIdentifier: String { String(describing: self) }
private var hostingController: UIViewController!
func setup<Content: View>(view: Content) {
self.hostingController = UIHostingController(rootView: view)

👏 解決するチケット や Issue、内容 / Resolved Ticket or Issue, Contents

  • close #0

📝 関連する issue や Pull Requests / Related Issues or Pull Requests

  • #0
import Combine
import UIKit
class SampleViewController: UIViewController {
private var cancellables: Set<AnyCancellable> = []
@IBOutlet private var sampleView: UIView!
override func viewDidLoad() {
@hira22
hira22 / PlaceHolderTextEditor.swift
Last active December 3, 2021 08:00
SwiftUI TextEditor にプレースホルダーを設定する
import SwiftUI
struct PlaceHolderTextEditor: View {
var placeholderText: String
@State var text: String
var body: some View {
ZStack(alignment: .topLeading) {
if text.isEmpty {
Text(placeholderText)
@hira22
hira22 / exportJSON.gs
Last active September 17, 2020 22:39
Google SpreadSheet を JSONファイル に変換してファイルを配置するGAS
// メニューバーにアクションを設定する
function onOpen() {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const entries = [
{
name: "このシートをJSONファイルに変換&出力",
functionName: "exportJSON"
}
];
spreadsheet.addMenu("JSON変換", entries);
@hira22
hira22 / SortDictionary.swift
Last active January 15, 2020 07:43
DictionaryのSortは事前に配列をソートしておく
import Foundation
enum Gender {
case female
case male
case other
}
let array = [
(name: "Shun", gender: Gender.male),