These are chat archives for devslopes/swiftios9

25th
Oct 2015
Murat Cakmak
@muratcakmak
Oct 25 2015 00:00
If someone want to change the variable, she only allows to use set method that the implementer of the class provide.
Jack Davis
@jackd942
Oct 25 2015 00:00
_odometer is the variable being set when that code is called. The getter returns the value of _odometer
The odometer is just a go-between so that you’re not accessing _odometer directly
Mark Price
@spentak
Oct 25 2015 00:01
Upvote @jackd942
and @muratcakmak
Jesus Lopez De Nava
@lodena
Oct 25 2015 00:04
WOW! I get it now!
Thanks a lot!
:)
andyaf
@andyaf
Oct 25 2015 02:28
Thanks @spentak how do I connect my storyboard view to my IBM Outlet? I tried CMD + drag as mentioned in your tutorials
itsalexbrown
@itsalexbrown
Oct 25 2015 02:44
@andyaf try control + drag
Go to assistant editor so your code and story board a side-by-side, and while holding the control button, drag from a stroyboard element over to your code
Mark Price
@spentak
Oct 25 2015 04:09
Hi @duliodenis welcome
Sketchy Swift
@HardcoreIOS
Oct 25 2015 15:55
@spentak
This message was deleted
@itsalexbrown How do I upload a video
Mark Price
@spentak
Oct 25 2015 16:02
Here? YouTube link
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:05
Where
I didn’t receive any link
Jake Krajewski
@sachio222
Oct 25 2015 16:17
suuup.
just started my new gig so I haven't xcoded in like a week
jonesin but have no time
Mark Price
@spentak
Oct 25 2015 16:18
@itsalexbrown nice GIF!!
@sachio222 hows that gig going?
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:18

Ok, here is my question.
In our second initializer method, when we call it in a subclass, do we need to call the previous superclass initializer methods on our new initializer.

class Person {
    var age = 20
    var name = "swift"

    init(name: String, age: Int) // Focus here {
        self.name = name
        self.age = age
    }
}

class Clothes: Person {
    var shirt = "T-Shirt"

    init(shirt: String, name: String, age: Int){
// Over here , do we ^need to call ^ “name: String, age: Int” in this //initializer
        self.shirt = shirt
        super.init(name: "Swift", age: 30)
    }
}

var info = Person(name: "Jon", age: 30)

var info2 = Clothes(shirt: "T-Shirt", name: "Swift", age: 45)

I am trying to say is it necessary to call the previous method names in our second initializers
thanks
@spentak

Jake Krajewski
@sachio222
Oct 25 2015 16:19
good man, it's a contract UX gig for a fortune 500 company
Mark Price
@spentak
Oct 25 2015 16:20
@HardcoreIOS you should try testing this without calling the parent initializer and try with it. see what happens
Jake Krajewski
@sachio222
Oct 25 2015 16:20
Fortune 10 company I mean
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:21
ok
// Do u mean this
class Person {
    var age = 20
    var name = "swift"

    init() {

    }
}

class Clothes: Person {
    var shirt = "T-Shirt"

    init(shirt: String, name: String, age: Int) {
        self.shirt = shirt
    }
}
Jake Krajewski
@sachio222
Oct 25 2015 16:23
As a perk I can work remotely :) But it's just a short gig. Going to interview with GoPro and Magic Leap this upcoming week. Ideally, I want to design and code my own apps tho
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:27
@spentak Don’t leave me here
Jake Krajewski
@sachio222
Oct 25 2015 16:34
try it out @HardcoreIOS what errors do you get if any? give him some time to answer, but also try to figure it out
Are you ask, do you have to init the superClass in a subclass?
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:35
@sachio222 I am not getting an error. Just a question
Jake Krajewski
@sachio222
Oct 25 2015 16:35
if you write a parent class that requires an init, say each Person class has an age
and then you write a subclass as an astronaut that is a person, wouldn't the astronaut need an age as well?
if you called astronaut, what would be that person's age? You have to define it somehow
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:37
class Person {
    var age = 20
    var name = "swift"

    init(name: String, age: Int) // Focus here {
        self.name = name
        self.age = age
    }
}

class Clothes: Person {
    var shirt = "T-Shirt"

    init(shirt: String, name: String, age: Int){
// Over here , do we ^need to call ^ “name: String, age: Int”  in this //initializer
        self.shirt = shirt
        super.init(name: "Swift", age: 30)
    }
}

var info = Person(name: "Jon", age: 30)

var info2 = Clothes(shirt: "T-Shirt", name: "Swift", age: 45)
Do we need call name: String, age: Int in this example above, or can we leave it
Jake Krajewski
@sachio222
Oct 25 2015 16:39
I see - well let me ask you about your logic first
is a clothes a type of person?
A superhero is a type of person. A shirt is a type of clothes.
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:40
LOL, Just an example
Jake Krajewski
@sachio222
Oct 25 2015 16:42
ok, well it makes more sense if we use real examples. Let's call it personWithClothes then. So in the personWithClothes init
you're saying, tell me what his shirt name is, what's the person's name, and what's the age
oh I finally get your question
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:44
@sachio222 One minute, coming up with an example

@sachio222

class Person {
    var name = ""
    var age = 0

    init (name: String, age: Int) {
        self.name = name
        self.age = age
    }
}

class Superhero: Person {
    var skill = ""

    init(skill: String, name: String, age: Int) {
        self.skill = skill
        super.init(name: "Batman", age: 30)
    }
}

var anotherSuperhero = Superhero(skill: "Wining", name: "Superman", age: 25)

Here is your example

Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:51
How can I have my own custom initializer in my subclass
I only want to have skill
Why am I getting 2 options when I called convenience @sachio222
Clasś.jpg
Jake Krajewski
@sachio222
Oct 25 2015 16:53
ok, so what you're saying in your subclass superhero is interesting, and it doesn't make complete sense
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:54
LOL :)
Jake Krajewski
@sachio222
Oct 25 2015 16:54
in the example code, you're saying no matter what your super hero name and age is, call him batman
and make him 30
in the screen shot you just showed, you're getting two inits because superhero is a subclass of person.
it either will take a name and age you give it
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:56
How can I make sure that only skill is called when I call Superhero. What kind of initializer do I use
Jake Krajewski
@sachio222
Oct 25 2015 16:56
well, that's what your code is saying
not what you wanted
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:56
Oh “Not exactly was for the other answer."
Jake Krajewski
@sachio222
Oct 25 2015 16:56
your code is saying, ok, give me any skill name and age, and I'll give it a skill and call him batman and make him 30
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:56
Correct
Jake Krajewski
@sachio222
Oct 25 2015 16:57
so if you want a superhero to be a person, and all persons have a name and age, then if you create a superhero with only a skill...
why does it need to be a person?
if you want a super hero to have a name and an age, then you can ask for them all at once
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:57
How can I make sure that only skill is called when I call Superhero. What kind of initializer do I use. I don’t want name and age to be called when I open the parentheses. Only skill
That is my main question
Do I need to make the variables private or something
Jake Krajewski
@sachio222
Oct 25 2015 16:58
no, I see what you're saying - and if sounds like you want skill to be a subclass of person?
Sketchy Swift
@HardcoreIOS
Oct 25 2015 16:59
Yah
Jake Krajewski
@sachio222
Oct 25 2015 16:59
I see, I see
you don't need to do that. make skill a property of the Person class
by making it a subclass, you're actually a skill IS a person
and shares EVERYTHING a person has, but with more
Sketchy Swift
@HardcoreIOS
Oct 25 2015 17:00
Let me see...
Jake Krajewski
@sachio222
Oct 25 2015 17:00
if you want a person to have a skill, then you can make it a property of a person. You can say var skill: String = ""
then you can say person.skill = "bo-skills"
and now your person has a skill
if you want skill to be a subclass of person, then you're saying a person has age and name, but a skill has an age and name, and a name for the skill
Sketchy Swift
@HardcoreIOS
Oct 25 2015 17:01
cass.jpg
Now i am getting an error
Jake Krajewski
@sachio222
Oct 25 2015 17:03
try moving super.init up one line
before self.skill
Sketchy Swift
@HardcoreIOS
Oct 25 2015 17:04
Yessssssss, I GOT IT
ddddd.jpg
This is what I wanted
✋ High five
Jake Krajewski
@sachio222
Oct 25 2015 17:05
great job
Sketchy Swift
@HardcoreIOS
Oct 25 2015 17:05
Thanks for all the help!
Jake Krajewski
@sachio222
Oct 25 2015 17:05
no problem
you're going to need to do getters and setters if you want to make any of your superheros named something and with an age though
good luck
andyaf
@andyaf
Oct 25 2015 17:48
A big help, I realized I had miss connected on of the elements on my storyboard. Thanks @itsalexbrown
ShayanAmin
@ShayanAmin
Oct 25 2015 18:33
hi to all , i am shayan . i have developed Android Applications since 2014 but today i want learn swift and programming for ios Applications .
Mark Price
@spentak
Oct 25 2015 18:34
Welcome @ShayanAmin
ShayanAmin
@ShayanAmin
Oct 25 2015 18:35
Tnx
Tarek
@TarekSalama
Oct 25 2015 23:29
@spentak I dunno if this approach is good or bad. I tend to save a copy of reusable pieces of code since it can be hard to memorize sometimes. Like the function you created for adding sounds and dragging stuff around. Of coarse I don’t blindly reuse the code again.
tbonesteak
@tbonesteak
Oct 25 2015 23:31
yeah I was wondering the same thing. Would it be good or bad practice to copy code for things like NSUserDefaults, Coredata, ImagePicker, etc. since a lot of it is the same and kinda boiler plate?