supotuco (32) [Avatar] Offline
#1
In 11.1.1 I'm not sure what state we are saving. I ran the app with preserving the application state and without preserving the application state, on the book's branch and mine. In all cases the tab preference is saved when you background the app and foreground it again. But in neither case is it saved after killing the process. What am I supposed to see or do?
Craig Grummitt (49) [Avatar] Offline
#2
Hi Supotuco.

The state gets saved when the app is moved to the background. You can move the app to the background for example, by pressing the home button. If you force close the app - for example with the stop button (or the play button to restart your app), the state won't get saved. Most of the time, though - users in the real world will be simply moving your app to the background, so this isn't such a big problem.

So to test that state is saving correctly, you want to:
1. Change the state
2. Press the home button
3. Press the play button to run the app again and see if the state has changed.

Hope this helps!
supotuco (32) [Avatar] Offline
#3
I tested it before the changes and I had the same behavior. That is why I'm still confused.
Craig Grummitt (49) [Avatar] Offline
#4
Hi Supotuco.

Here are some animated gifs that hopefully will help clear this up. In both gifs I do the same:
1. Run the bookcase app (Xcode play button)
2. Change tabs to the second tab.
3. Close the app (Home button in the simulator)
4. Run the bookcase app again (Xcode play button)

The difference is what I see when I run the app again in step 4.

In the following animated GIF, I am running the app from the Chapter10.7.TabBarController branch of the repo.

As we aren't saving app state yet on the tab bar controller, the app opens to the first tab:

image

But in the following animated GIF, I am running the app from the Chapter11.1.UserPreferences branch of the repo.

As we ARE saving app state now on the tab bar controller, the app opens to the second tab:

image

Does this help?
supotuco (32) [Avatar] Offline
#5
Thanks for the gifs. Now I see what I was missing.
Craig Grummitt (49) [Avatar] Offline
#6
Great!
442146 (2) [Avatar] Offline
#7
AT LINE: import SwiftyJSON (!): 'Module compiled with Swift 4.0.3 cannot be imported in Swift 4.1: /user/"directory"'

What does this error mean in the SwiftJSON.h file?
I though Swift didn't use headers.
Craig Grummitt (49) [Avatar] Offline
#8
Hi 42713! Sorry it's taken a few days to get back to you. I believe you maybe have posted in the wrong area - I don't think this problem was related to the Chapter11.1.UserPreferences branch (at least it shouldn't be!) What branch are you having problems with? I suspect it may be branch Chapter14.1.WebServiceData at least.

Have you updated the SwiftyJSON framework in the repo? Basically, if you have Carthage installed, you should navigate to your project folder in the terminal and call:

carthage update


There's a more detailed explanation on page 426 of the book.
442146 (2) [Avatar] Offline
#9
Thanks Craig! That does make sense. Xcode projects seem to rely heavily on frameworks. Carthage, cocoa pods etc. I just didn't realize that was the direction you were going. The beginners books haven't mentioned using them yet. Although, I know a youtube host that uses them in his tutorials.

I'm not great with forums. So, yes I probably did post in the wrong area. This is my first time here! smilie Thanks again!
Craig Grummitt (49) [Avatar] Offline
#10
No problem, and welcome! Glad that sounds like it helped. Yes, frameworks can be great, as they save you from reinventing the wheel, but they can also be a pain, as your project becomes dependent on third parties.