# Video Tutorial: Beginning Realm on iOS Part 1: Getting Started

**URL:** <https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593>\
**Category:** 🎓 Courses & Articles\
**Created:** [June 6, 2016, 2:01pm UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593 "2016-06-06T14:01:10Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![icanzilb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/icanzilb/32/109333_2.png) [@icanzilb](https://forums.kodeco.com/u/icanzilb)\
**Post date:** [June 6, 2016, 2:01pm UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/1 "2016-06-06T14:01:11Z")

</div>

This video tutorial covers modeling a basic data model class with Realm.

 
* * *
 This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/3479-beginning-realm-on-ios/lessons/2](https://www.raywenderlich.com/3479-beginning-realm-on-ios/lessons/2)

---

<div class="post-metadata">

**Author:** ![fordee](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fordee/32/105896_2.png) [@fordee](https://forums.kodeco.com/u/fordee)\
**Post date:** [June 7, 2016, 6:14am UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/2 "2016-06-07T06:14:59Z")

</div>

Great tutorial. I’m just starting to use Realm in a project, so this video tutorial series has come just in time. I was wondering why your primaryKey class method returns an optional String? since it will always have a value. Shouldn’t it be non-optional?

---

<div class="post-metadata">

**Author:** ![icanzilb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/icanzilb/32/109333_2.png) [@icanzilb](https://forums.kodeco.com/u/icanzilb)\
**Post date:** [June 7, 2016, 6:55am UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/3 "2016-06-07T06:55:37Z")

</div>

Hi fordee, it returns `String?` because you may choose not to have a primary key for your object. By default (e.g. if you do not override this method) it returns `nil`.

---

<div class="post-metadata">

**Author:** ![fordee](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fordee/32/105896_2.png) [@fordee](https://forums.kodeco.com/u/fordee)\
**Post date:** [June 7, 2016, 8:56am UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/4 "2016-06-07T08:56:41Z")

</div>

Thanks. Yes, I can see in the documentation they say it returns an optional. However, when I implement it in my code, I return a non-optional String and the compiler doesn’t complain. Strange. I guess it can return a non-optional as well.

---

<div class="post-metadata">

**Author:** ![icanzilb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/icanzilb/32/109333_2.png) [@icanzilb](https://forums.kodeco.com/u/icanzilb)\
**Post date:** [June 7, 2016, 9:15am UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/5 "2016-06-07T09:15:02Z")

</div>

Yes, but this is a Swift implementation detail not related to Realm - you can use non-Optional values when an Optional is expected.

---

<div class="post-metadata">

**Author:** ![delonn](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/delonn/32/1088_2.png) [@delonn](https://forums.kodeco.com/u/delonn)\
**Post date:** [June 7, 2016, 11:50am UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/6 "2016-06-07T11:50:25Z")

</div>

Thanks for the great tutorial subject! Have been waiting for it.

Question: If i were to use Int for “id”, does the primaryKey also return “id”?

---

<div class="post-metadata">

**Author:** ![icanzilb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/icanzilb/32/109333_2.png) [@icanzilb](https://forums.kodeco.com/u/icanzilb)\
**Post date:** [June 7, 2016, 12:08pm UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/7 "2016-06-07T12:08:08Z")

</div>

Yes, the `primaryKey()` method returns the name of the property; you can see an example here: [https://realm.io/docs/swift/latest/#primary-keys](https://realm.io/docs/swift/latest/#primary-keys)

---

<div class="post-metadata">

**Author:** ![chicojobs](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/chicojobs/32/111841_2.png) [@chicojobs](https://forums.kodeco.com/u/chicojobs)\
**Post date:** [June 9, 2016, 4:59pm UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/8 "2016-06-09T16:59:06Z")

</div>

Hello and compliments for the tutorial, I’m enjoying every episode of it!  
Now that RealmSwift has reached 1.0, I took the opportunity to start fiddling with it again.

As far as I can tell, it looks like storing native Swift Array or NSArray is not supported. So, for example, if you have the following:

`class Person: Object { dynamic var friends: [String]? }`

you must find a way to decompose / serialize that array in order to store it in Realm, right? Otherwise it would crash at runtime saying that NSArray is not a supported type.

Since in Foundation we have NSJSONSerializer for free and since NSData is a type supported in Realm, I came up with a little workaround and I’ll be happy to hear your opinion about it. Basically I’m converting the array to NSData everytime it gets updated

[sorry for the bad code formatting]

`  
class Person: Object {  
dynamic var value = NSData()

```
dynamic var friends: [String]! {
    didSet {
        try! self.value = NSJSONSerialization.dataWithJSONObject(oldValue, options: .PrettyPrinted)
    }
}

override static func ignoredProperties() -> [String] {
    return ["friends"]
}

```

}  
`

Could it be a good practice? Do you think there is a significant overhead with all of this serialize/unserialize thing?

Thank you and, again, many compliments to you and all of the RW guys! 🙂

---

<div class="post-metadata">

**Author:** ![icanzilb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/icanzilb/32/109333_2.png) [@icanzilb](https://forums.kodeco.com/u/icanzilb)\
**Post date:** [June 9, 2016, 5:22pm UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/9 "2016-06-09T17:22:24Z")

</div>

Thanks! An effective way to store arrays is to wrap the type you want to have an array of. E.g. if you’d like to have an array of strings in your model you could wrap String in a Realm type - there’s a complete example with code here: [ios - Storing an array of strings using Realm's RLMArray - Stack Overflow](http://stackoverflow.com/a/31730894/208205)

---

<div class="post-metadata">

**Author:** ![chicojobs](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/chicojobs/32/111841_2.png) [@chicojobs](https://forums.kodeco.com/u/chicojobs)\
**Post date:** [June 10, 2016, 8:13am UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/10 "2016-06-10T08:13:31Z")

</div>

Thank you! 🙂

---

<div class="post-metadata">

**Author:** ![bozo](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bozo/32/81494_2.png) [@bozo](https://forums.kodeco.com/u/bozo)\
**Post date:** [August 1, 2016, 1:03pm UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/11 "2016-08-01T13:03:11Z")

</div>

realm/util/features.h’ file not found is coming when i compile Project. how i can solve it please ?

---

<div class="post-metadata">

**Author:** ![icanzilb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/icanzilb/32/109333_2.png) [@icanzilb](https://forums.kodeco.com/u/icanzilb)\
**Post date:** [August 1, 2016, 1:20pm UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/12 "2016-08-01T13:20:59Z")

</div>

I haven’t seen this error so my best guess is to reinstall the Realm pod

---

<div class="post-metadata">

**Author:** ![mortjac](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/mortjac/32/47139_2.png) [@mortjac](https://forums.kodeco.com/u/mortjac)\
**Post date:** [November 10, 2016, 9:51am UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/13 "2016-11-10T09:51:56Z")

</div>

I like Realm and I like your tutorial. But the cocoapod gives me trouble because I’m on a MacOS Beta. I had a lot of trouble removing all references of “pods”.

---

<div class="post-metadata">

**Author:** ![icanzilb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/icanzilb/32/109333_2.png) [@icanzilb](https://forums.kodeco.com/u/icanzilb)\
**Post date:** [November 11, 2016, 8:31am UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/14 "2016-11-11T08:31:02Z")

</div>

We use CocoaPods because it’s usually easier for most of the readers to get working on the project faster 🙂

---

<div class="post-metadata">

**Author:** ![roberson](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/roberson/32/55725_2.png) [@roberson](https://forums.kodeco.com/u/roberson)\
**Post date:** [January 27, 2017, 12:34pm UTC](https://forums.kodeco.com/t/video-tutorial-beginning-realm-on-ios-part-1-getting-started/15593/15 "2017-01-27T12:34:37Z")

</div>

Excellent tutorial. You would have an updated version of your project for this version of Swift 3.
