Skip to content

Instantly share code, notes, and snippets.

View ryo-takahashi's full-sized avatar
👻
こんにちは

ryo-takahashi ryo-takahashi

👻
こんにちは
View GitHub Profile
@ryo-takahashi
ryo-takahashi / DOCUMENT.md
Created February 23, 2025 05:45 — forked from y-takagi/DOCUMENT.md
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

#include <SwitchControlLibrary.h>
const int TX_LED_PIN = 30;
void setup() {
pinMode( TX_LED_PIN, OUTPUT );
SwitchControlLibrary();
}
void loop() {
SwitchControlLibrary().pressButton(Button::A); // Aボタンを押す
@ryo-takahashi
ryo-takahashi / index.js
Created July 8, 2022 08:23
大量にウォレットアドレス用意するマン
const ethers = require("ethers");
const fs = require("fs");
const createCount = 150;
let createdAddress = [];
for (let i = 0; i < createCount; i++) {
const wallet = new ethers.Wallet.createRandom();
createdAddress.push(wallet.address);
}
document.designMode="on";
@ryo-takahashi
ryo-takahashi / gist:2bc0c4b12be52a4a0c059b436c37862b
Created August 26, 2020 01:21
ランダムな文字列を生成するコマンド
cat /dev/urandom | base64 | fold -w 32 | head -n 1
@ryo-takahashi
ryo-takahashi / gist:c80dba2b21d50c876637af8259b5cdbb
Created April 7, 2020 06:48
iOS スリープ状態にさせないための制御コード
https://developer.apple.com/documentation/uikit/uiapplication/1623070-isidletimerdisabled
@ryo-takahashi
ryo-takahashi / UIColorで使っているRGBの値を取得する.swift
Created March 25, 2020 15:42
UIColorで使っているRGBの値を取得する
// 1
UIColor.red.ciColor.red
UIColor.red.ciColor.green
UIColor.red.ciColor.blue
UIColor.red.ciColor.alpha
// 2
UIColor.yellow.cgColor.alpha
// 3
@ryo-takahashi
ryo-takahashi / iOS アプリ内からカラーテーマを変更する.swift
Last active March 24, 2020 09:27
iOS アプリ内からカラーテーマを変更する
if #available(iOS 13.0, *) {
switch type {
case .light:
UIApplication.shared.keyWindow?.overrideUserInterfaceStyle = .light
case .dark:
UIApplication.shared.keyWindow?.overrideUserInterfaceStyle = .dark
case .conformedSystem:
UIApplication.shared.keyWindow?.overrideUserInterfaceStyle = UITraitCollection.current.userInterfaceStyle
case .unknown: break
}
@ryo-takahashi
ryo-takahashi / recuisiveFetchRandomJapanLocation.swift
Last active March 18, 2020 01:33
7桁の郵便番号数字をランダムに生成し、日本の実在住所が取得できるまで再帰的に実行する
import CoreLocation
let geoCoder = CLGeocoder()
var challangeCount = 0
func recursiveFetchJapanLocation(completion: (() -> ())?) {
let randomAddress = Int.random(in: 0..<9999999)
let randomAddressString = String(format: "%07d", randomAddress)
challangeCount += 1
ffmpeg -i $1 -r 12 $2