# When would you use custom objectId in your projects?

**URL:** <https://community.parseplatform.org/t/when-would-you-use-custom-objectid-in-your-projects/2385>\
**Category:** ParseSwift SDK\
**Tags:** object-id\
**Created:** [January 24, 2022, 7:23am UTC](https://community.parseplatform.org/t/when-would-you-use-custom-objectid-in-your-projects/2385 "2022-01-24T07:23:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayson](https://community.parseplatform.org/user_avatar/community.parseplatform.org/jayson/32/679_2.png) [@jayson](https://community.parseplatform.org/u/jayson)\
**Post date:** [January 24, 2022, 7:23am UTC](https://community.parseplatform.org/t/when-would-you-use-custom-objectid-in-your-projects/2385/1 "2022-01-24T07:23:12Z")

</div>

Just out of curiosity, when would you guys use the custom objectId feature in your projects?

What would be the best use of the feature?

thanks,

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [January 24, 2022, 3:10pm UTC](https://community.parseplatform.org/t/when-would-you-use-custom-objectid-in-your-projects/2385/2 "2022-01-24T15:10:06Z")

</div>

IMO, custom objectId’s are useful in a few scenarios (I’m sure there are others):

- If you have a local database that creates the uuid already and you are using a Parse Server as your cloud sync
- If your client app can create and distribute data offline and use Parse to sync when it’s online
- You data comes from a separate database that you sync with cloud

In the above cases, you can also just keep separate fields for `objectId` and `uuid` (other database identifier), but some people prefer to minimize fields. If data transmission doesn’t happen offline or the Parse Server is the only place that syncs your data, I don’t think you need to use custom objectId, but that’s just my opinion…

It’s easy to do replace `objectId` when a custom value in the Swift SDK. If you are interested you can look how I do it in one my of my projects.

Just take over the encoding of your `ParseObjects` by declaring the method below in your object:

> <https://github.com/netreconlab/ParseCareKit/blob/b39debcfc8df90f213b83664099526e61e7215b9/Sources/ParseCareKit/Objects/PCKPatient.swift#L96-L103>

`encodeVersionable` eventually calls `encodeObjectable`. When encoding for parse use replace objectId with `uuid` and vice-versa locally. I do this in 2-steps, when I decode a local CareKit object that has it’s own `uuid`, I use it to replace the objectId of a `ParseObject`:

> <https://github.com/netreconlab/ParseCareKit/blob/b39debcfc8df90f213b83664099526e61e7215b9/Sources/ParseCareKit/Objects/PCKPatient.swift#L269-L277>

> <https://github.com/netreconlab/ParseCareKit/blob/b39debcfc8df90f213b83664099526e61e7215b9/Sources/ParseCareKit/Protocols/PCKObjectable.swift#L80-L88>

So `encodeObjectable` looks like:

> <https://github.com/netreconlab/ParseCareKit/blob/b39debcfc8df90f213b83664099526e61e7215b9/Sources/ParseCareKit/Protocols/PCKObjectable.swift#L206-L226>

You may need to setup code to access the Swift SDK encoders/decoders. That’s simple as well as you can just leverage that static methods of one of your `ParseObject`'s:

> <https://github.com/netreconlab/ParseCareKit/blob/b39debcfc8df90f213b83664099526e61e7215b9/Sources/ParseCareKit/PCKUtility.swift#L89-L102>

---

<div class="post-metadata">

**Author:** ![jayson](https://community.parseplatform.org/user_avatar/community.parseplatform.org/jayson/32/679_2.png) [@jayson](https://community.parseplatform.org/u/jayson)\
**Post date:** [January 25, 2022, 6:07am UTC](https://community.parseplatform.org/t/when-would-you-use-custom-objectid-in-your-projects/2385/3 "2022-01-25T06:07:51Z")

</div>

thank you for this detailed reply. It’s a lot for me to go through but I am. I didn’t think about the offline part of it which makes a lot of sense now that you mention it. I’m looking into how you set up PCK as well. Learning quite a bit from you.

thanks again. 🙂
