Learn Swift for Beginners – Programming Challenges [w/ subs]



00:00:00 – hi it's Chris here so you've just gone
00:00:02 – through all of those in the learn Swift
00:00:04 – for beginners series now there's 17 in
00:00:06 – total so far and although there's a lot
00:00:09 – more to learn with Swift programming you
00:00:12 – do know a lot already to be dangerous
00:00:14 – and to do quite a bit with it so in this
00:00:17 – video I'm going to introduce to you
00:00:19 – three programming challenges that you
00:00:21 – can do today just using what you've
00:00:24 – learned so far and they're very very
00:00:27 – doable so don't shy away from them and
00:00:29 – they're going to help you reinforce what
00:00:31 – you already know help you identify
00:00:33 – things that you might not have grasped
00:00:36 – and furthermore it helps you memorize
00:00:39 – all of the syntax and the structure of
00:00:42 – the programming language all the
00:00:43 – keywords and things like that I tell you
00:00:46 – this from firsthand knowledge because
00:00:47 – when i learned iOS programming i just
00:00:49 – read a book front to back and when i try
00:00:52 – to build something I realized that I
00:00:54 – couldn't remember a lot of what I read
00:00:56 – so it wasn't until I started typing
00:00:58 – things out hitting roadblocks and you
00:01:01 – know actually physically typing it out
00:01:03 – did everything start to glue and meld
00:01:06 – together in my mind so these exercises
00:01:08 – are going to help you do that and
00:01:10 – furthermore once you complete these
00:01:12 – three challenges you can get your name
00:01:15 – and a link to your twitter profile
00:01:17 – listed right here below this section in
00:01:20 – our wall of same now right now there's
00:01:23 – nobody because I'm just launching this
00:01:24 – page today and all you have to do is
00:01:28 – complete the three challenges up here
00:01:30 – and then you're going to click this blue
00:01:32 – button to tweet this out and proclaim
00:01:34 – your victory and also to notify me so
00:01:37 – I'm going to add your name manually down
00:01:39 – here and you will be immortalized on
00:01:42 – this learn Swift to page so the URL for
00:01:45 – this page is in this description below
00:01:48 – if you're watching this on youtube or if
00:01:50 – you're already on this page then you
00:01:51 – just need to scroll down the URL as code
00:01:53 – with Chris calm / learn dash Swift okay
00:01:57 – now i'm also going to quickly go through
00:02:00 – the three challenges with you just to
00:02:02 – introduce them and to tell you what you
00:02:04 – have to do or you can just go ahead jump
00:02:07 – to the page right now and download these
00:02:08 – files because there are instructions in
00:02:10 – each of these files okay so let's just
00:02:13 – hop
00:02:14 – into the first playground here you're
00:02:16 – going to need Xcode in order to complete
00:02:19 – these challenges so for challenge 1
00:02:22 – you've got two arrays with a bunch of
00:02:24 – strings in each array and what I want
00:02:27 – you to do is to write a function that
00:02:29 – accepts a single string parameter and
00:02:32 – this function is going to output true or
00:02:34 – false if the input string is in either
00:02:38 – of the two arrays then return true if
00:02:42 – the input is not in any of the race is
00:02:46 – not in both the arrays at all then
00:02:48 – return false so here are two examples if
00:02:50 – it's cat then you would return true
00:02:52 – because it's here if it's cow cows in
00:02:55 – neither of these arrays so you're going
00:02:57 – to return false okay so you might have
00:03:00 – to go back and review the syntax to
00:03:02 – write a function and type parameters and
00:03:04 – such but it's going to be good practice
00:03:06 – for you okay so here's the second one
00:03:11 – it's going to get a little bit harder
00:03:12 – with each one so this one I'm giving you
00:03:15 – a class called string caterpillar and I
00:03:18 – want you to implement the add function
00:03:20 – and the goal function so the add
00:03:24 – function takes in a piece of text and
00:03:26 – what you're going to do is you're going
00:03:29 – to store that piece of text every time
00:03:30 – add is called and this piece of text
00:03:34 – gets passed and you're going to store
00:03:36 – that piece of text somehow and then when
00:03:38 – someone calls the goal function you're
00:03:40 – going to output all of the pieces of
00:03:43 – text that have been added by this add
00:03:47 – function you're going to output them all
00:03:48 – in one line using a print statement so
00:03:51 – this is the code statements that are
00:03:56 – going to get executed you don't have to
00:04:00 – edit any of this all you have to do is
00:04:02 – you know you're going to be completing
00:04:04 – this part right here this class
00:04:06 – definition so given this code declaring
00:04:10 – a new string caterpillar object and then
00:04:12 – adding H adding e ll 0 and then call and
00:04:16 – go the expected output down here in the
00:04:19 – console would be hello and then there's
00:04:22 – some bonus credit if you want to create
00:04:24 – a custom initializer that where you can
00:04:27 – pass in
00:04:27 – a string so you can read about that ok
00:04:31 – so the third one is right here and this
00:04:37 – one's a little more complicated so what
00:04:40 – we have here we have a person class you
00:04:43 – don't need to do anything with this it's
00:04:45 – got a name property and you've got a
00:04:48 – book class it's got title and author you
00:04:51 – don't have to do anything with this
00:04:52 – class either but what you do have to do
00:04:55 – is you have to implement this class
00:04:57 – called library so this library has got
00:05:00 – two dictionaries okay so one dictionary
00:05:03 – here is the library catalog so it's got
00:05:06 – this book ID and then as a key and then
00:05:10 – the value is an actual book right and
00:05:12 – the book object obviously has a title
00:05:14 – and an author so here's another book
00:05:17 – that's the book ID and that's the book
00:05:20 – object with the title and the author and
00:05:23 – then we've got another dictionary that
00:05:26 – so far is empty the key is a string it's
00:05:29 – going to be the book ID and the value is
00:05:32 – a person object which represents the
00:05:34 – person who has checked out that book and
00:05:36 – I want you to implement a couple of
00:05:38 – functions here a few the first one is
00:05:41 – search by title you're going to pass in
00:05:43 – a title of a book now that's not the
00:05:47 – book ID ok that's the actual title and
00:05:49 – you have to implement this code which
00:05:54 – checks for several things so first of
00:05:56 – all if the book ID is not or sorry the
00:06:00 – book title is not in the catalog at all
00:06:03 – is it doesn't exist in this catalog
00:06:07 – dictionary then you return the string
00:06:08 – not in catalog now if it is in the
00:06:13 – catalog and it's available then you
00:06:15 – return the string available and if it is
00:06:18 – checked out by someone then you put
00:06:21 – checked out by and then the name so this
00:06:25 – you're not going to put n AME here
00:06:28 – you're going to put the actual name of
00:06:31 – the person that exists in this property
00:06:34 – right here remember you do have this
00:06:37 – dictionary which contains you know the
00:06:39 – person object that checked out
00:06:41 – so you're going to have to check both
00:06:42 – dictionaries that's a little hint for
00:06:44 – you and next you're going to implement
00:06:47 – two other functions check out and check
00:06:50 – in okay so pretty self-explanatory here
00:06:53 – again if the book doesn't exist in the
00:06:55 – catalog you shouldn't be able to check
00:06:57 – it out so you're going to return the
00:06:58 – string book doesn't exist if the book is
00:07:02 – currently already checked out and it it
00:07:05 – does exist in the catalog then you're
00:07:06 – going to return error colon book already
00:07:08 – checked out and finally if the book is
00:07:13 – in the catalog and it is available as in
00:07:17 – its not checked out by anybody yet then
00:07:19 – you're going to return successfully
00:07:20 – checked out you're going to actually add
00:07:23 – the person to the dictionary well I
00:07:26 – don't want to give too much away but
00:07:27 – that this is essentially what you want
00:07:30 – to output given this case and check in
00:07:35 – similar I'm not going to go through it
00:07:37 – pretty much the opposite of check out
00:07:39 – you're going to be returning the book
00:07:40 – and again that's all all your editing is
00:07:44 – this stuff in the library class
00:07:48 – definition you don't have to modify
00:07:50 – anything below here this is just the the
00:07:54 – sample statements and the expected
00:07:56 – output so here we're going to declare a
00:07:58 – new library we're going to declare to
00:08:00 – borrowers curious george and Mark Twain
00:08:03 – and then there's going to be a bunch of
00:08:05 – statements and it's going to do the
00:08:09 – printing of the result that comes back
00:08:11 – from the functions you're going to
00:08:13 – implement and this is the expected
00:08:15 – output that you should see from that
00:08:17 – print statement then it's going to
00:08:19 – execute this one and print it out and
00:08:21 – you're going to you know look in the
00:08:23 – console down here to see this message so
00:08:27 – what you want to do is implement the
00:08:30 – functions up here in the library class
00:08:33 – and if you've done it correctly you know
00:08:35 – returning the correct output here
00:08:38 – depending on the scenarios then running
00:08:41 – this series of statements your it's
00:08:45 – going to yield the expected output in
00:08:48 – the console so you can check that now
00:08:50 – once you've successfully completed all
00:08:52 – of the challenges what I want you to do
00:08:55 – is go back down to the wall of fame here
00:08:57 – and click this button it's going to
00:09:00 – launch a little window and you can tweet
00:09:02 – it's going to notify me I'm going to see
00:09:05 – it i'm going to add your name and your
00:09:07 – profile below here in the wall of fame
00:09:09 – and it's also going to help me get the
00:09:11 – word out for this page a little bit more
00:09:14 – so i can grow the code with chris brand
00:09:16 – so I do thank you for that and I thank
00:09:19 – you for learning with me so go ahead and
00:09:22 – give it a try if you get stuck comment
00:09:25 – here in this page below I'll help you
00:09:27 – out thanks for watching and I'll see you
00:09:29 – next time bye for now


Video Url:
http://youtu.be/U4hGXWKfYy0

Comments

comments