-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// ContentView.swift | ||
// Example | ||
// | ||
// Created by Ahmed Ali on 24/05/2024. | ||
// | ||
|
||
import SwiftUI | ||
import RealmSwift | ||
import RealmDebugger | ||
|
||
class DatabaseManager { | ||
init() { | ||
do { | ||
let realm = try Realm() | ||
|
||
let animalModel1 = AnimalModel() | ||
animalModel1.name = "Dog" | ||
|
||
let animalModel2 = AnimalModel() | ||
animalModel2.name = "Cat" | ||
|
||
let animalModel3 = AnimalModel() | ||
animalModel3.name = "Horse" | ||
|
||
let countryModel1 = CountryModel() | ||
countryModel1.name = "Argentina" | ||
countryModel1.capital = "Buenos Aires" | ||
|
||
let countryModel2 = CountryModel() | ||
countryModel2.name = "Brazil" | ||
countryModel2.capital = "Brasília" | ||
|
||
let taskModel1 = TaskModel() | ||
taskModel1.name = "Do 30 mins of yoga" | ||
|
||
try realm.write { | ||
realm.add(animalModel1) | ||
realm.add(animalModel2) | ||
realm.add(animalModel3) | ||
realm.add(countryModel1) | ||
realm.add(countryModel2) | ||
realm.add(taskModel1) | ||
} | ||
} catch { | ||
print(error) | ||
} | ||
} | ||
} | ||
|
||
struct ContentView: View { | ||
private var manager = DatabaseManager() | ||
|
||
var body: some View { | ||
VStack { | ||
Text("Hello, world!") | ||
Button("Open Realm Debug View") { | ||
RealmDebugger.presentRealmDebuggerView() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// AnimalModel.swift | ||
// Example | ||
// | ||
// Created by Ahmed Ali on 24/05/2024. | ||
// | ||
|
||
import RealmSwift | ||
|
||
class AnimalModel: Object, Identifiable { | ||
@Persisted(primaryKey: true) var id: ObjectId | ||
@Persisted var name: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// CountryModel.swift | ||
// Example | ||
// | ||
// Created by Ahmed Ali on 24/05/2024. | ||
// | ||
|
||
import RealmSwift | ||
|
||
class CountryModel: Object, Identifiable { | ||
@Persisted(primaryKey: true) var id: ObjectId | ||
@Persisted var name: String | ||
@Persisted var capital: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// TaskModel.swift | ||
// Example | ||
// | ||
// Created by Ahmed Ali on 24/05/2024. | ||
// | ||
|
||
import RealmSwift | ||
|
||
class TaskModel: Object, Identifiable { | ||
@Persisted(primaryKey: true) var id: ObjectId | ||
@Persisted var name: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters