Skip to content

Instantly share code, notes, and snippets.

View tsuzukihashi's full-sized avatar
🎮

Ryo Tsuzukihashi tsuzukihashi

🎮
View GitHub Profile
@tsuzukihashi
tsuzukihashi / BannerView.swift
Last active June 14, 2023 12:41
SwiftUI Admob Banner
import SwiftUI
import GoogleMobileAds
enum BannerType {
case main
var id: String {
switch self {
case .main:
return ""
@tsuzukihashi
tsuzukihashi / toCMSampleBuffer.swift
Last active November 27, 2023 00:13
UIView to CMSampleBuffer (UIViewをCMSampleBufferに変換するExtension)
import UIKit
import CoreMedia
extension UIView {
func toCMSampleBuffer() -> CMSampleBuffer? {
let scale: CGFloat = UIScreen.main.scale
let size: CGSize = .init(width: bounds.width * scale, height: bounds.height * scale)
guard let pixelBuffer = makeCVPicelBuffer(scale: scale, size: size) else { return nil }
defer {
CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: 0))
@wilg
wilg / parallel_map.swift
Last active February 9, 2024 20:21 — forked from DougGregor/parallel_map.swift
Swift async/await implementation of a parallel map
import Foundation
// https://gist.github.com/DougGregor/92a2e4f6e11f6d733fb5065e9d1c880f
extension Collection {
func parallelMap<T>(
parallelism requestedParallelism: Int? = nil,
_ transform: @escaping (Element) async throws -> T
) async rethrows -> [T] {
let defaultParallelism = 2
let parallelism = requestedParallelism ?? defaultParallelism
// Created by gil_birman on 11/22/19.
import Combine
import FirebaseFirestore
import FirebaseStorage
import Foundation
enum FirebaseCombineError: Error {
case encodeImageFailed
case nilResultError
@pteasima
pteasima / Auth+Combine.swift
Last active February 6, 2021 13:52
Firebase + Combine extensions
import FirebaseAuth
import Combine
extension PublishersNamespace where Base: FirebaseAuth.Auth {
var currentUser: AnyPublisher<User?, Never> {
let userSubject = PassthroughSubject<User?, Never>()
let handle = base.addStateDidChangeListener { auth, user in
userSubject.send(user)
}
@y-takagi
y-takagi / DOCUMENT.md
Last active April 29, 2024 16:36
iOSでデータを永続化する方法

How to save data in iOS

この投稿では、iOSのファイルシステムについて理解し、データを永続化(iCloud含む)する方法を紹介する。尚、サンプルコードは動かない可能性もあるので参考程度にして下さい。

iOS File System

アプリがファイルシステムとやり取り出来る場所は、ほぼアプリのサンドボックス内のディレクトリに制限されている。新しいアプリがインストールされる際、インストーラーはサンドボックス内に複数のコンテナを作成し、図1に示す構成をとる。各コンテナには役割があり、Bundle Containerはアプリのバンドルを保持し、Data Containerはアプリとユーザ両方のデータを保持する。Data Containerは用途毎に、さらに複数のディレクトリに分けられる。アプリは、例えばiCloud Containerのように、実行時に追加のコンテナへのアクセスをリクエストすることもある。

IMG_0017_RESIZE.png

図1. An iOS app operating within its own sandbox