Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
自主勉強会_Realm
Search
奥村元春
January 18, 2024
Programming
70
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
自主勉強会_Realm
HOPTER TECH SCHOOLにて開催された学生自主勉強会(Realm)にて使用した資料です。
奥村元春
January 18, 2024
More Decks by 奥村元春
See All by 奥村元春
Lightning Talk Battle #2 230106
mshr1106
0
220
ミスランカー
mshr1106
0
270
Other Decks in Programming
See All in Programming
Oxlintのカスタムルールの現況
syumai
6
1.1k
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
570
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
270
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
180
Vite+ Unified Toolchain for the Web
naokihaba
0
320
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.3k
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.3k
ふつうのFeature Flag実践入門
irof
7
4k
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
400
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
270
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
net-httpのHTTP/2対応について
naruse
0
500
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
6.9k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
840
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1.1k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
620
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
310
Faster Mobile Websites
deanohume
310
31k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
Into the Great Unknown - MozCon
thekraken
41
2.6k
Transcript
学生自主勉強会 Realm 奥村 元春
Realmはオープンソースのローカルデータベース 現在下記の言語に対応 • Objective-C • Swift • Java (Androidのみ) •
Kotlin (Androidのみ) • C# (Xamarin, Win32, UWP) • JavaScript (Node.js, React Native) • C++ • Dart (Flutter) Realmとは 2019年春頃にMongoDBが買収。2023年9月26日にRealmからAtlas Device SDKに名称変更。
•SQLiteや純正のCore Dataよりも高速 •クラス定義がそのままテーブル定義となる •プライマリキー(主キー)が指定できる •オートインクリメントを設定できない 特徴(RealmSwift)
SQLiteや純正のCore Dataよりも高速 特徴(RealmSwift) 1秒間で20,000件のレコードがインサート可能 1秒間で約50件条件に合うレコードを 取り出すクエリを捌ける
プライマリキー(主キー)が指定できる 特徴(RealmSwift) テーブル内でレコードを一意(重複しない)に識別することができるように 指定される項目(カラム) 指定したカラムに対してデータが追加されると、 自動的に1ずつ値を付与してくれる機能。 オートインクリメントを設定できない
ターミナル CocoaPods導入 sudo gem install cocoapods うまくいかない場合 sudo gem install
-n /usr/local/bin cocoapods インストール終了後 pod setup
Xcodeのプロジェクトを新規作成し、作成したプロジェクトファイルにターミナルで移動 RealmSwift導入 cd 【プロジェクトファイルのパス】 Xcodeを終了し、その場所で pod init ディレクトリにPodfileが出現
ディレクトリに生成されたPodfileを開いて RealmSwift導入 target ‘【プロジェクト名】’ do end 上記が書いてある場所の間に pod 'RealmSwift' もしくは
pod 'RealmSwift', ‘【バージョン】’
注意 RealmSwift導入 Xcodeのバージョンによって、導入できるRealmのバージョンが異なります。 RealmSwift v10.31.0 ~ 10.33.0 ⇨ Xcode v13.1~14.1 RealmSwift v10.34.0
~ 10.37.2 ⇨ Xcode v13.3~14.2 RealmSwift v10.38.0 ~ 10.39.1 ⇨ Xcode v13.4~14.3 RealmSwift v10.41.0 ~ 10.45.2 ⇨ Xcode v14.1~15.1.0 RealmSwift v10.45.3 ~ ~ ~ ~ ⇨ Xcode v14.2~15.2.0 対応バージョンまとめ https://github.com/realm/realm-swift/releases
保存後、さっきと同じプロジェクトファイルの場所で RealmSwift導入 pod install インストール終了後、画像のようになっていれば成功 【プロジェクト名】.xcworkspaceでXcodeを起動
実装:テーブルの作成 上のメニューバーの File ⇨ New ⇨ File ⇨ SwiftFile ⇨
名前をRealmData.Swift ⇨ Create RealmData.Swiftに import RealmSwift class Hoge: Object { @Persisted var name: String = "" // 名前 @Persisted(primaryKey: true) var id: Int = 0 // id(プライマリキー) } ViewController.Swiftに import RealmSwift
実装:データの追加 ViewController.SwiftのviewDidLoad()内に let realm = try! Realm() for i in
1...5 { let hogeAdd = Hoge() hogeAdd.name = "岐阜 \(i)郎" hogeAdd.id = i try! realm.write { realm.add(hogeAdd,update:.modified) } }
実装:データの取得 ViewController.Swiftのデータ追加の後ろに let hogesRead = realm.objects(Hoge.self) for hoge in hogesRead
{ print("name: \(hoge.name)") } 実行して、デバッグログに下記のように表示されれば成功
実装:データの更新 ViewController.Swiftのデータ取得の後ろに for i in 1...hogesRead.count { try! realm.write {
hogesRead[i - 1].name = "岐阜 \(i)郎太" } } for hoge in hogesRead { print("更新後name: \(hoge.name)") }
実装:データの更新 実行して、デバッグログに下記のように表示されれば成功
実装:データの削除 ViewController.Swiftのデータ更新の後ろに if let hoge = hogesRead.first { try! realm.write
{ realm.delete(hoge) } } for hoge in hogesRead { print("削除後name: \(hoge.name)") }
実装:データの削除 実行して、デバッグログに下記のように表示されれば成功
Welcome to the Atlas Device SDK Docs 参考URL https://www.mongodb.com/docs/realm/ https://en.wikipedia.org/wiki/Realm_(database)
Realm (database) Realm is Now Atlas Device SDKs https://www.mongodb.com/blog/post/realm-now-part-atlas-platform? _ga=2.126710021.983132505.1701072256-17544333.1701072256 Realmについて知る① https://qiita.com/reo0612/items/ed72bd6b5c9e60d6cd82
爆速な “Realm” は本番投入に値するか 参考URL https://medium.com/eureka-engineering/%E7%88%86%E9%80%9F%E3%81%AA-realm- %E3%81%AF%E6%9C%AC%E7%95%AA%E6%8A%95%E5%85%A5%E3%81%AB%E5%80%A4%E 3%81%99%E3%82%8B%E3%81%8B-6cdc4a3f2828 Releases - realm/realm-swift
https://github.com/realm/realm-swift/releases 【Swift】CocoaPodsでRealmをインストールする方法 & importできないときの対処法。 https://qiita.com/chan_naruwo/items/798e30d840bdca3edd8c