# Chapter 7, page 347 cant dispatch .NSManagedObjectContextDidSave

**URL:** <https://forums.kodeco.com/t/chapter-7-page-347-cant-dispatch-nsmanagedobjectcontextdidsave/36826>\
**Category:** Core Data by Tutorials\
**Created:** [November 22, 2017, 7:40pm UTC](https://forums.kodeco.com/t/chapter-7-page-347-cant-dispatch-nsmanagedobjectcontextdidsave/36826 "2017-11-22T19:40:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon79415772](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@anon79415772](https://forums.kodeco.com/u/anon79415772)\
**Post date:** [November 22, 2017, 7:40pm UTC](https://forums.kodeco.com/t/chapter-7-page-347-cant-dispatch-nsmanagedobjectcontextdidsave/36826/1 "2017-11-22T19:40:38Z")

</div>

Type ‘String’ has no member ‘NSManagedObjectContextDidSave’

expectation(  
forNotification: .NSManagedObjectContextDidSave,  
object: coreDataStack.mainContext) {  
notification in  
return true  
}

I change it to

expectation(forNotification: NSNotification.Name.NSManagedObjectContextDidSave.rawValue, object: coreDataStack.mainContext) { notification in  
return true  
}

The test fails with following error message:  
XCTAssertNil failed: “Error Domain=com.apple.XCTestErrorDomain Code=0 “(null)”” - Save did not occur

---

<div class="post-metadata">

**Author:** ![bobcampbell](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/bobcampbell/32/76288_2.png) [@bobcampbell](https://forums.kodeco.com/u/bobcampbell)\
**Post date:** [November 30, 2017, 1:58am UTC](https://forums.kodeco.com/t/chapter-7-page-347-cant-dispatch-nsmanagedobjectcontextdidsave/36826/2 "2017-11-30T01:58:13Z")

</div>

I saw the error

> Type ‘String’ has no member ‘NSManagedObjectContextDidSave’

Looked up and found this thread, but no working answer.

I looked at the finished project and it builds and runs.

I then ran FileMerge between my working version and the final project.

I noticed in the project.pbxproj noticed this difference:

```
			SWIFT_VERSION = 3.0;

```

The version of the book I have is suppose to be swift 4.0 I did in Xcode:

- select project file
- select the CampgroundManagerTests target
- select the “Build Settings” group
- type “swift” in the search window
- scroll down to “Swift Language Version” change it to “4.0”

The test then builds and runs using the code from the book:

```
expectation(forNotification: .NSManagedObjectContextDidSave,
    object: coreDataStack.mainContext) {
    notification in
    return true
}

```

---

<div class="post-metadata">

**Author:** ![anon79415772](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@anon79415772](https://forums.kodeco.com/u/anon79415772)\
**Post date:** [December 5, 2017, 2:52pm UTC](https://forums.kodeco.com/t/chapter-7-page-347-cant-dispatch-nsmanagedobjectcontextdidsave/36826/3 "2017-12-05T14:52:35Z")

</div>

Thank you @bobcampbell! It solved the compile error.  
The save test still doesn’t work though but I believe that the problem is somewhere else in my code!  
Thanks again!

---

<div class="post-metadata">

**Author:** ![nyquist](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/nyquist/32/109325_2.png) [@nyquist](https://forums.kodeco.com/u/nyquist)\
**Post date:** [December 12, 2017, 1:22pm UTC](https://forums.kodeco.com/t/chapter-7-page-347-cant-dispatch-nsmanagedobjectcontextdidsave/36826/4 "2017-12-12T13:22:20Z")

</div>

This error blew an hour of my time, thank you Bob!! I went through the same steps as you, with the exception of the FileMerge, that was a great idea. Thanks for the _very_ _clear_ steps as to resolve.

---

<div class="post-metadata">

**Author:** ![brianlawson](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/brianlawson/32/81494_2.png) [@brianlawson](https://forums.kodeco.com/u/brianlawson)\
**Post date:** [December 26, 2017, 8:37pm UTC](https://forums.kodeco.com/t/chapter-7-page-347-cant-dispatch-nsmanagedobjectcontextdidsave/36826/5 "2017-12-26T20:37:06Z")

</div>

Even after following @bobcampbell’s instructions I could not get my program to pass the save tests. Various attempts at finding differences between my code and the finished version of the code (which works) did not find any so I decided to start over with the chapter. I trashed my entire 07-unit-testing folder and extracted a new copy from the .zip file.

The first thing I did after opening the starter project was check the language used for the test project. It was already set to Swift 4.0. When I added the Swift file TestCoreDataStack the test project’s language setting changed to Swift 3.0. I reset it back to 4.0 then went through the chapter’s exercises again. This time everything worked properly.

I don’t know why the language changed when the new .swift file was added (Xcode bug maybe?) but, making sure to reset it before adding any new code seems to have resolved my issues.

If anyone else is still having problems passing the save test(s) after making the language change, try starting from a fresh copy of the project.

---

<div class="post-metadata">

**Author:** ![warplydesigned](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/warplydesigned/32/110598_2.png) [@warplydesigned](https://forums.kodeco.com/u/warplydesigned)\
**Post date:** [April 13, 2018, 5:06am UTC](https://forums.kodeco.com/t/chapter-7-page-347-cant-dispatch-nsmanagedobjectcontextdidsave/36826/6 "2018-04-13T05:06:02Z")

</div>

Thanks @bobcampbell solved my problem and the tests pass now. This was the first thread that showed up in google search so 2 seconds to solve the problem woohoo 🙂

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [May 8, 2018, 11:42am UTC](https://forums.kodeco.com/t/chapter-7-page-347-cant-dispatch-nsmanagedobjectcontextdidsave/36826/7 "2018-05-08T11:42:49Z")

</div>

Closed on May 8, 2018, 11:42am UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
