These are chat archives for devslopes/swiftios9

14th
Nov 2015
Sketchy Swift
@HardcoreIOS
Nov 14 2015 00:08
cool
@jackd942 Is it very important to use extensions often in your apps?
@spentak ^
JPROFFICIAL
@JPROFFICIAL
Nov 14 2015 00:14
Does anyone here know how to make specific details for a specific item on a tableView?
Not really understanding for some reason.
Jack Davis
@jackd942
Nov 14 2015 00:19
What do you mean specific details? You mean a details view for a given item?
JPROFFICIAL
@JPROFFICIAL
Nov 14 2015 00:22
Exactly
Jack Davis
@jackd942
Nov 14 2015 00:23
If you have all of your data in a custom class, then you do a prepareForSegue and pass the object through to the details view controller
like for the movie app.
hang on a sec
look at my ViewController and MovieDetailsVC
The data in this case is handled in CoreData
Movie.swift and Movie+CoreDataProperties.swift
Jack Davis
@jackd942
Nov 14 2015 00:28

```func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var movie: Movie!
movie = movies[indexPath.row]

    performSegueWithIdentifier("MovieDetailsVC", sender: movie)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "MovieDetailsVC" {
        if let movieDetailsVC = segue.destinationViewController as? MovieDetailsVC {
            if let movie = sender as? Movie {
                movieDetailsVC.movie = movie
            } 
        }
    }
}

```

didSelectRowAtIndexPath assigns movie from the array movies and then calls performSequeWithIdentifier
prepareForSegue sends that particular movie over to the DetailsVC and assigns it to the movie variable declared in the details vc
hope that makes sense
JPROFFICIAL
@JPROFFICIAL
Nov 14 2015 00:32
It does, just trying to relate it over to my project. for some reason I am just having the hardest time trying to impliment this. Maybe because I am not using coreData. Let me see here. Thank you so much @jackd942
Jack Davis
@jackd942
Nov 14 2015 00:32
it would work the same without core data
just use custom class for whatever object you are trying to pass over
it can take a minute to get your head around it
JPROFFICIAL
@JPROFFICIAL
Nov 14 2015 00:34
How did you do that slide from the add?
Add button you can slide back to cancel
Jack Davis
@jackd942
Nov 14 2015 00:34
navigation controller
with a nav controller, it’s as simple as
@IBAction func cancelBtnTapped(sender: UIButton) {
        self.navigationController?.popViewControllerAnimated(true)
    }
Jack Davis
@jackd942
Nov 14 2015 00:50
Did that help at all @JPROFFICIAL ?
JPROFFICIAL
@JPROFFICIAL
Nov 14 2015 00:59
@jackd942 Im trying. Yeah it helped alot, I just for some reason am not able to wrap my head around this data transfer. Really sucky
Jack Davis
@jackd942
Nov 14 2015 00:59
haha…I’ve been there
hang in there and it’ll all “click"
JPROFFICIAL
@JPROFFICIAL
Nov 14 2015 01:03
I am going to DM you @jackd942
Jack Davis
@jackd942
Nov 14 2015 01:03
This message was deleted
ok
Felix Barros
@BluePhoenix
Nov 14 2015 01:23
This message was deleted

@jackd942 Im trying. Yeah it helped alot, I just for some reason am not able to wrap my head around this data transfer. Really sucky

Though I am still fairly new at this, the way I understand it is, you are moving from View Controller A to View Controller B by pressing a button. So, before it segues you use prepareForSegue to transfer the information. To do that, you cast the destinationViewController to the View Controller you are expecting (B) and then you need something inside B to store the data you want to use. Right?

Jack Davis
@jackd942
Nov 14 2015 01:41
you have to have a variable in the destination view controller to contain the object being passed, yes. So, if you were passing say a pokemon object you would have a var pokemon: Pokemon! declaration in the detination vc.
In the Pokemon example, here is the code for prepareForSegue
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "PokemonDetailVC" {
            if let detailsVC = segue.destinationViewController as? PokemonDetailVC {
                if let poke = sender as? Pokemon {
                    detailsVC.pokemon = poke
                }
            }
        }
    }
so in this instance you are checking the segue identifier first, then assigning the destination View controller (which is a UIViewController being cast to a PokemonDetailVC) to detailsVC
then assigning your object that is selected in the tableview or collection view to a variable (poke) in this case…and since sender is any object, you have to cast it to a Pokemon
then you assign the pokemon variable of the detailsVC the object
detailsVC.pokemon = poke
Jack Davis
@jackd942
Nov 14 2015 01:50
So in re-reading your question, you are correct:)
Felix Barros
@BluePhoenix
Nov 14 2015 01:50
Awesome. The Pokedex designs you posted earlier look great, btw.
Thanks :)
Jack Davis
@jackd942
Nov 14 2015 01:51
when you say that you cast the destinationViewController to the view controller you are expecting could use a little clarification...
the reason you have to cast it is that in prepareForSegue, if you don’t cast it, it will just be a UIViewController.
if that makes sense.
and thanks
Felix Barros
@BluePhoenix
Nov 14 2015 01:53
Yeah, in which case Xcode will warn that ViewController doesn’t have .pokemon defined (or a similar error).
Jack Davis
@jackd942
Nov 14 2015 01:53
I believe that’s correct
Felix Barros
@BluePhoenix
Nov 14 2015 01:53
Cool
Jack Davis
@jackd942
Nov 14 2015 02:02
@jackd942
oh…and BTW, it’s important that your segue is from your ViewController to the DetailsVC and not your cell to the DetailsVC.
If you drag a segue over from your cell to the detailsVC, your object won’t make it across when doing a prepareForSegue/performSegueWithIdentifier
Felix Barros
@BluePhoenix
Nov 14 2015 02:06
Interesting, that is a good point. I am guessing it is because the cells don’t have access to the same members as the DetailsVC then.
Jack Davis
@jackd942
Nov 14 2015 02:12
You’re kicking off performSegueWithIdentifier manually from didSelectCellAtIndexPath in your ViewController
Felix Barros
@BluePhoenix
Nov 14 2015 02:16
I still haven’t gotten to this lesson yet, though I am pretty excited to be building a Pokedex
Jack Davis
@jackd942
Nov 14 2015 02:16
I had the same problem in the movie app when I first wrote it and it seemed like it took me forever to figure it out
Felix Barros
@BluePhoenix
Nov 14 2015 02:17
Since I have taken some courses before, I am trying to figure out which lesson I want to start with on this one, I don’t like skipping, but I want to stay engaged.
Yeah, it seems like one of those things that can easily trip you up if you don’t know about it, so I appreciate the heads up.
Jack Davis
@jackd942
Nov 14 2015 02:19
I’ve got to say…I’ve got quite a bit of experience with a few other languages (not an expert by any means), but it has been beneficial to go through his lessons without skipping…even if I just work through them pretty fast. Plus a lot of experimentation along the way.
a lot of practical stuff there
Felix Barros
@BluePhoenix
Nov 14 2015 02:21
yeah, I think I read that in the previous chat. Nice work. :)
That is the main reason I don’t like skipping the earlier ones, because each instructor has something else they add to the mix (how they preview the layouts, how they use the constraints, etc and the same is true for non-UI stuff)
Jack Davis
@jackd942
Nov 14 2015 02:22
yep…my biggest hurdle has been all the autolayout stuff more so than the code/classes, etc.
Felix Barros
@BluePhoenix
Nov 14 2015 02:23
Yeah. It is really cool how they did it, but I am still adjusting to how to get it just right.
Jack Davis
@jackd942
Nov 14 2015 02:23
no doubt
Felix Barros
@BluePhoenix
Nov 14 2015 02:24
especially when considering the changing orientations :D makes you appreciate the nice looking apps you see in the store.
Jack Davis
@jackd942
Nov 14 2015 02:29
Yes it does. A lot of work goes into things that look really simple
Felix Barros
@BluePhoenix
Nov 14 2015 02:29
:smile:
Aizaz Khaja
@aizkhaj
Nov 14 2015 03:34

hey guys, wondering if any of you got this problem while doing the calculator app: I got to the point where we are testing out the

func processOperation(op: Operation) {
        playSound()

        if currentOperation != Operation.Empty {
            //Run some math
        } else {
            //This is the first time an operator has been pressed
            leftValStr = runningNum
            runningNum = ""
            currentOperation = op
        }

after building it, in the video it works as intended, where upon pressing the operator, it will allow you to show a new number press. However if I press an operator, it crashes/takes me to this error in AppDelegate.swift:

Screen Shot 2015-11-13 at 9.30.39 PM.png
Felix Barros
@BluePhoenix
Nov 14 2015 03:36
@metalhe4der Almost looks like a broken Interface Builder outlet to me… but, do you know what the error says in the console? (Bottom of the middle pane, right side)
Aizaz Khaja
@aizkhaj
Nov 14 2015 03:37
hmm let me take a look
Felix Barros
@BluePhoenix
Nov 14 2015 03:38
ok
You can also look for any broken outlets like this http://i.stack.imgur.com/4Xvet.png
Aizaz Khaja
@aizkhaj
Nov 14 2015 03:41
this is what im seeing in debug console:
Sketchy Swift
@HardcoreIOS
Nov 14 2015 03:41
@metalhe4der Did it work
Could you post it
Aizaz Khaja
@aizkhaj
Nov 14 2015 03:41
Screen Shot 2015-11-13 at 9.40.45 PM.png
Sketchy Swift
@HardcoreIOS
Nov 14 2015 03:41
Ok, let me look
Aizaz Khaja
@aizkhaj
Nov 14 2015 03:42
im going to try and go through my outlets, but i have to step outside for a bit, so i can only get in touch with my phone til im back
thanks guys
Sketchy Swift
@HardcoreIOS
Nov 14 2015 03:42
Could you post a screen shot of your view controller
;)
Felix Barros
@BluePhoenix
Nov 14 2015 03:42
Yeah, almost looks like you have multiple IBActions mapped. But I could be wrong.
See you later
Aizaz Khaja
@aizkhaj
Nov 14 2015 03:44
@BluePhoenix actually you were right with the broken outlets
i checked and there were two broken ones :D
what gave away my problem for such a solution btw?
Felix Barros
@BluePhoenix
Nov 14 2015 03:44
Awesome, those can be pretty pesky. Glad it was that.
Well, running into that issue multiple times helps. ;)
But mainly, it was about half way through that last screenshot. “Unrecognized selector sent to instance 0x… , it was also suspicious that the same thing happened in the following line.
seems like it was trying to send onMultiplyPress to a selector that was not connected
Aizaz Khaja
@aizkhaj
Nov 14 2015 03:47
yeah it was mainly with my divide and multiply!
so that makes sense
failing is the best educator haha
Felix Barros
@BluePhoenix
Nov 14 2015 03:48
yeah, haha
Sketchy Swift
@HardcoreIOS
Nov 14 2015 15:36

-NSUserDefaults video.
Hello everyone,
What is the difference between setting an object and setting a value?

 NSUserDefaults.standardUserDefaults().setValue(“Red", forKey: "color")

VS

NSUserDefaults.standardUserDefaults().setObject("Red", forKey: "color")

Thanks!

Also, what exactly happens when you do NSUserDefaults.standardUserDefaults().synchronize()
@spentak ^
Mark Price
@spentak
Nov 14 2015 15:58
Values are for value types and object is for reference types
Sketchy Swift
@HardcoreIOS
Nov 14 2015 15:59
Meaning what exactly...
ok, so we can’t set an object for the colors? @spentak
Mark Price
@spentak
Nov 14 2015 16:58
In your example you are setting a string for key color
Jesus Lopez De Nava
@lodena
Nov 14 2015 19:39
@spentak, congratulations on your new baby!!!
I have a question (I'm 100% new to oop & swift)... In lecture 47 "Exercise: build an app using oop", you want us to create a game class to manage the game state instead of using the view controller. Does this mean that the view controller class will only have the @IBOutlet vars and @IBAction funcs in it, and then I should create the rest of the needed functions, etc, in the game class? Being new to OOP this is kind of confusing.
Thanks for your help.
Felix Barros
@BluePhoenix
Nov 14 2015 19:46

@lodena I think you would likely need a var in your view controller that will keep track of the data, as well. Though @spentak or others can confirm better

It would probably look something like:

class ViewController: UIViewController {
    var gameModel = GameModel()

    @IBOutlet@IBAction …

}

if your game model class is:

class GameModel {
}
Mark Price
@spentak
Nov 14 2015 19:48
@lodena The more you can modularize the better. The less logic that manipulates data or manages state you are writing in your view controllers the better. View controllers should just be like a traffic signal that directs traffic where it needs to go. sometimes this is not always possible. but the key here is modularization is the best practice
Jesus Lopez De Nava
@lodena
Nov 14 2015 19:51
@spentak, so @IBOutlet vars and @IBAction funcs must still stay in the View Controller right?
Jesus Lopez De Nava
@lodena
Nov 14 2015 20:06
So, if for instance I press a button and I need to produce a sound, then its @IBAction func should call another function from the game class to play the sound instead of coding it directly into the @IBAction func?
@BluePhoenix , thanks for your previous reply.
Felix Barros
@BluePhoenix
Nov 14 2015 20:12
You are welcome :)
Homith
@Homith
Nov 14 2015 22:47
Good Morning Everyone
Just new to the course
Wanted to drop in and say hello
Aizaz Khaja
@aizkhaj
Nov 14 2015 22:50
Welcome @Homith!
Mark Price
@spentak
Nov 14 2015 23:32
welcome @Homith
Homith
@Homith
Nov 14 2015 23:54
Hi :) I am rather excited indeed. Making my Boom App :) hehe