Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
自主勉強会_Realm
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
奥村元春
January 18, 2024
Programming
79
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
230
ミスランカー
mshr1106
0
270
Other Decks in Programming
See All in Programming
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
170
phperだってパンチカードでコーディングしたい
o0h
PRO
0
340
Domain-Driven Transformation
hschwentner
2
2.3k
Next.js: The final boss of Web Performance
guaca
0
280
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
気持ちぃ〜角丸 Squircle
ryu1013
0
310
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
280
Featured
See All Featured
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
570
It's Worth the Effort
3n
188
29k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
630
Facilitating Awesome Meetings
lara
57
7.2k
Speed Design
sergeychernyshev
33
2.2k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Building the Perfect Custom Keyboard
takai
2
910
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
300
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
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