yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Objective-C iPhone Programming Lesson 6 - Saving Basic Data


3m read
·Nov 3, 2024

Processing might take a few minutes. Refresh later.

Hey guys, this is my kids along with a video on iPhone development. So this is our sixth tutorial, and in this tutorial I'm going to be showing you how to save data that your app stores.

So we're going to be saving the state of a switch, so whether it's switched on or off, and we'll be saving the kind of the progress of a slider. So let's create a new project, and when we go to view-based application, I'll call it Save Test.

All right, and I'll just type in the interface builder stuff. We're going to have to IV outlets, so you know we're going to have both a UI slider, call it slide A, and we're going to have a UI switch, we'll call it switch 1. We're going to have one universal action that's going to be data changed, and both objects are going to call this.

So I'll show you what I mean in a segment. We'll go into the interface builder project, and we're going to hook everything up like you would normally expect. So we will drag this in and drag listen, and we're going to hook obviously this up, and we're going to hook a slider up like, right let's slide off like this.

And here's the tricky part; we want both of these objects when the data gets changed to call our data changed. So if we go in the inspector and we say value changed, we can drag it to data changed. Now here's the cool thing: multiple objects can call the same action.

So here on the slider value change, we're also going to call the data changed, and I think that's pretty cool. So here we go. Now let's make this not out of 0 just for usability, and make this that off at off.

And now we will implement our data changed method. Let's go here and we're going to use nice user defaults to do this. So we're going to declare user defaults and make it NSUserDefaults standard. Use defaults, we're going to see default set object and this number. Remember, with poor switch 1 is on, and you'll see what this 1000 a second.

And I'll save it for the key s1. And in viewDidLoad, we're going to load the same thing. So I'm just going to copy the bolts, paste in our viewDidLoad. I'm going to say switch on set on default object for key s1 will value.

Okay, an object for key needs an object. It can't take a bowl or an integer or a float to any scalar; it needs to take a pointer to an Objective-C object. So that's why we're using NSNumber to do that. NSNumber is the numbers wrapper class or the scalar wrapper class, I'll call it anyway.

So we're doing that work, and we have all that stuff set up, so now it should see the state of our switch. So if you're on it, it's gonna open the simulator, and here we will set our switch to on.

And now if we kill it, just to make this on the Watson, the iPad simulator, since the kids very strange, now it's on. And if you sign it back to off, how about we slide it on again? We close it and we open it one more time, it'll be on.

So there we go, we know it works. Ah, it's not just multitasking that's doing it. So let's also do the progress indicator, and this is quite similar. Here on our seed methods, we'll say set object, and it's number number with holding number float slider 1 and leave you can just do, can you do value?

All right, hopefully, that's fine. I'll call sl1; the variable names can get confusing when we say slider 1 set value defaults on your freaky ass at water float.

Yeah, okay, and two. Now if we run it, it should save also our slider state. So it's running; let's put our slider. It's Amanda thing; it's trying to switch off, close it, kill it. You know, so clean it's running in the background even though it's not, because that's how I oh I stairs.

And if we run it now, you'll have the state we see, and it's pretty awesome that way. So here's how the falls works; we're just setting an object and reading that object later on.

Um, you can also do nifty things like given default values for that, but that's for a different tutorial some other day. And before this tutorial is over, I have a question for all of you guys because I know a lot of my subscribers are from the age of maybe 12 to 16.

And I want to know who here has Black Ops, because, um, I just got the game; I played it a little bit, and it doesn't seem that great...

More Articles

View All
Failing Fast Isn't Really Failure – It's Accelerated Learning | Astro Teller| Big Think
Failure, seen properly, is just a recognition of fast learning. So I have training wheels, which I try to put on this concept within X, to try to help everyone get comfortable with the idea. Here’s an example. You’re working on a project. It either has a…
The TRUTH About Shark Tank REVEALED! (Behind The Scenes)| Shark Tank's Kevin O'Leary
It had never been done before. Nobody had ever done this before and we got it done. We’re all stuck in this call at Hotel California. We went in, we never came out. During the entire season that we shot [Music] [Music], it ain’t bragging if it’s true. I m…
Worked example: Determining the effect of temperature on thermodynamic favorability | Khan Academy
Let’s do a worked example where we calculate the standard change in free energy, ΔG⁰, for a chemical reaction. For our reaction, let’s look at the synthesis of ammonia gas from nitrogen gas and hydrogen gas at 25 degrees Celsius. ΔH⁰ for this reaction is…
Getting Water in the Arctic | Life Below Zero
[Music] Not everything goes the way you want it to go. You don’t get to choose how life unfolds; you just get to live it. [Music] Looks like I’ve got good moving water, but it looks like it’s out there quite a ways right now here in Kavik. This is the cha…
Using related volumes | Solid geometry | High school geometry | Khan Academy
[Instructor] We’re told that all of the following figures have the same height. All of the figures except for B have square bases. So that’s a square base, that’s a square, that’s a square, and that’s a square. All of the figures except for C are prisms. …
What humanity will gain by going to Mars | Leland Melvin
[Music] So, for humans to live on Mars and not just making a lot of potatoes and live off the potatoes for a while, it’s just the habitat, the systems itself for a robust life support system that’s going to keep you alive for this, you know, long period o…