# Cannot use mutating member on immutable value: function call returns immutable value: why cannot call mutating func directly on return value?

**URL:** <https://forums.swift.org/t/cannot-use-mutating-member-on-immutable-value-function-call-returns-immutable-value-why-cannot-call-mutating-func-directly-on-return-value/53579>\
**Category:** Using Swift\
**Created:** [November 18, 2021, 10:06pm UTC](https://forums.swift.org/t/cannot-use-mutating-member-on-immutable-value-function-call-returns-immutable-value-why-cannot-call-mutating-func-directly-on-return-value/53579 "2021-11-18T22:06:06Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![young](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/young/32/7878_2.png) [@young](https://forums.swift.org/u/young)\
**Post date:** [November 19, 2021, 12:01am UTC](https://forums.swift.org/t/cannot-use-mutating-member-on-immutable-value-function-call-returns-immutable-value-why-cannot-call-mutating-func-directly-on-return-value/53579/3 "2021-11-19T00:01:24Z")

</div>

What you say make sense if the mutated value is used afterward. But for an `JSONEncoder`:

```swift
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .custom { date, encoder in
    var container = encoder.singleValueContainer()
    try container.encode(date.formatted(.iso8601)) // what happen here?
    // nothing more
    // the code read like none sense, illogical :( 
}

```

My guess is inside `container` it's "wired" so calling `.encode(...)` cause the change up in the `encoder`. So why would a "caller" need to use an intermediate `var`? Seems like unnecessary leaking of implementation details.

---

_[View the full topic](https://forums.swift.org/t/cannot-use-mutating-member-on-immutable-value-function-call-returns-immutable-value-why-cannot-call-mutating-func-directly-on-return-value/53579)._
