Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Start a free Basic trial
to watch this video
Good programmers know what to write. Great programmers know what to rewrite (and reuse)." The Android and iOS ecosystems are rich with open source libraries that are tried and true solutions to common problems. In an industry where things are constantly evolving and timing is so important, it's more important than ever that developers know how to work efficiently and prioritize what will make their apps succeed. We are going to look at some popular open source libraries for Android and iOS that every mobile developer should know about.
-
0:02
Okay.
-
0:02
Hi everybody.
-
0:04
Looks like the last few people are coming in.
-
0:06
So I think we're set to go.
-
0:08
Good afternoon and thank you for joining me here today.
-
0:11
My name is Ben Jakuben.
-
0:13
Today we're gonna talk about jump starting
-
0:14
your app development using open source software.
-
0:17
I'm a teacher at Treehouse.
-
0:19
We're an online education company.
-
0:21
And, I teach, primarily Android development and
-
0:24
a little bit of iOS development as well.
-
0:28
And we cover, besides app development, we
-
0:30
cover front end and back end web development.
-
0:33
And there's stuff on the back table there.
-
0:36
So on your way out walk by there and we've got some notebooks, stickers and some.
-
0:41
Cards for free trials so if you wanna give us a shoot we got a free month
-
0:45
we're at nutrition base video learn platform so, take
-
0:49
a card or just visit the website for free
-
0:51
trial and check us out, some of the stuff
-
0:53
we're gonna cover today is, we, we have full
-
0:56
length courses of video on, on the site as
-
0:58
well so you can follow there if you're interested.
-
1:01
ss Okay, so, why specifically did I, want
-
1:04
to talk about using open source software today?
-
1:07
Actuall [COUGH].
-
1:09
Well, so, before we get into it.
-
1:13
[LAUGH] I wanted to ask what everybody's experience
-
1:15
was with mobile development and open source software.
-
1:18
So just with a quick show of hands, can you show me how many of you have.
-
1:23
A little bit of Android experience?
-
1:26
Okay, and how about a lot of Android experience?
-
1:28
A few, okay.
-
1:29
And then, for iOS as well, how about a little bit if iOS experience.
-
1:33
Okay, and a lot of iOS experience?
-
1:35
Good, Good.
-
1:36
How many are currently using open source software
-
1:39
in some way or another in their projects?
-
1:43
Good, all right so, [LAUGH] I don't have to tell you too much about the why then,
-
1:47
but this is just one of my favorite quotes
-
1:49
from an open source advocate named Eric S Raymond.
-
1:52
This is from an early essay on open source software called Cathedral and the Bazaar.
-
1:55
And quote is just good programmers know, what to write but great ones know
-
1:59
what to rewrite and reuse and it's that reuse part that really speaks to me.
-
2:04
The other thing is you you don't really need
-
2:07
to do work that somebody else has already done.
-
2:10
if, [LAUGH] if, if they've already done it and it's been done better.
-
2:13
And it's being used and it's well tested.
-
2:16
Unless you wanna, learn more about it yourself but, if
-
2:19
you need to get something out the door and save time.
-
2:21
And wanna use something that's proven and trusted.
-
2:24
Then, that's when open sores can really help you out.
-
2:28
So yes, specifically just run through some of the pros and cons.
-
2:31
One of the things I really like about, using open
-
2:34
source software is that third bullet point learning from others.
-
2:38
Taking a look at how other people are writing code is, the best
-
2:41
way to figure out where I'm doing it wrong and where I can improve.
-
2:44
So, pulling down an open source library and looking at either
-
2:48
example projects or how they're, implementing what they're doing is a.
-
2:51
Great way for me to figure out how I could make myself a better programmer.
-
2:55
Speaking of development, making the world a better
-
2:57
place of course by, helping each other out.
-
3:00
another, are some disadvantages as well.
-
3:03
I'm sure, a lot of you have may have been bitten by some
-
3:05
of these specifically if you're using an open source library that gets abandoned.
-
3:10
It's very frustrated if you need to.
-
3:13
you, if you discover a bug or some update to your
-
3:16
platform comes out and your library you're using is no longer supported.
-
3:19
So you need to either, fix it yourself or find an alternative.
-
3:24
On the flip side of that, sometimes, a good
-
3:26
open source library will get sucked into the platform.
-
3:29
So for example, pull the refresh, there were a ton of open
-
3:32
source implementations of the pull to refresh control on both iOS and Android.
-
3:36
And now, both of those both platforms have a
-
3:39
pull or swipe to refresh control built into the APIs.
-
3:42
So, you still have to do some conversion, but it may be a little bit easier to
-
3:47
do it that way than trying to, come up with your own or fix somebody else's code.
-
3:53
The second bullet point might be hard to include, that.
-
3:57
Isn't quite as true so much anymore
-
3:59
with things like, Girdle and CocoaPods for dependency
-
4:02
management which we're gonna talk about in just
-
4:03
a minute, it's a lot easier to include
-
4:06
homosource projects in your own projects, but,
-
4:10
before such tools it, it was cumbersome there
-
4:13
was a, Of popular open source library called
-
4:17
320 for iOS and this is by Facebook.
-
4:20
An early version of the SDK.
-
4:23
And the documentation was, really long on how to
-
4:27
include in your project and you had to include like
-
4:29
15 different frameworks and you had to wire things up
-
4:31
and you had to set your flags a certain way.
-
4:34
And it was right with steps to fail, but now it's a one line CocoaPod.
-
4:38
You just pull it in and, and all the hard work is taken care of for you.
-
4:41
It's in your project and you can use it right
-
4:43
away, so, it's Thank goodness, [LAUGH] tools like that exist nowadays.
-
4:50
Another thing, this is an important one that, that I forget sometimes, but it's
-
4:56
Really important to remember is, open source does not just mean for your code.
-
5:00
Whether it's design assets you're after or photos or other materials you
-
5:04
wanna use within an app even, music or video, stock footage, things
-
5:08
like that you can really, add to the richness of your app
-
5:11
with the open source or the open license, like Creative Commons license.
-
5:16
Things that you can include as long as you.
-
5:18
Attribute it specifically and make sure that you follow the, open
-
5:22
source license that are set aside for those kind of things.
-
5:25
>> [COUGH].
-
5:27
>> And a specific example of this, I let's see.
-
5:31
Yesterday, I did a workshop on iOS and, Android development.
-
5:35
And, we developed a, very simple basic.
-
5:39
Weather app and I needed to get some weather icons for it and
-
5:42
I am not a designer, so I did not want to, draw anything myself.
-
5:45
So I took a look, I did a Google search
-
5:47
and there are plenty of free weather icons, of course.
-
5:50
Then I went to GitHub and took a look
-
5:52
as well, and I'm just gonna switch over to show,
-
5:58
Oh, let's see, let me go to GitHub and do it.
-
6:00
I just searched for weather icons and sure enough there are
-
6:03
a bunch of solutions for both, mobile platforms and the web.
-
6:07
I ended up taking, some of these from Kickstand
-
6:10
apps weather icons and they had these available in
-
6:15
PNG or SVG format and they're free to use
-
6:17
in your apps, free to modify as long as you.
-
6:20
Give them credit that you use their resources.
-
6:22
So, again, it's just a fantastic time saver,
-
6:24
whether you're, you know, using this to prototype
-
6:27
something quickly or if, if it's good enough
-
6:29
you that wanna use it in your final app.
-
6:30
You know, maybe you don't have design team that can, pump out
-
6:32
some assets for you quickly or maybe you don't wanna do it yourself.
-
6:35
[BLANK_AUDIO]
-
6:41
Okay, so briefly for the rest of the
-
6:43
talk here, we're gonna talk about three main things.
-
6:47
How do we know what's available, then how do
-
6:49
we add it to our projects, and then I'll just
-
6:51
give a, quick rundown of some of my, personal favorite
-
6:54
open source libraries I use in some of my projects.
-
6:57
[NOISE].
-
6:59
[LAUGH] so, one thing when you're just starting out.
-
7:03
Whether you're, a new developer or it's your first
-
7:06
time trying to find open source code you wanna use.
-
7:09
The question is, like, how do you even know what's out there.
-
7:12
And that's, with more and more coming out.
-
7:15
Every week it seems.
-
7:16
It's hard to stay on top of the constant flow of, new things to
-
7:20
try out, new controls and new things you wanna, include in your product somehow.
-
7:27
So what I try to do is, every time I sit down to, like implement
-
7:30
a new feature or maybe improve something
-
7:32
I ask myself, has somebody done this already.
-
7:35
And, I ask myself and I will ask other resources as well.
-
7:39
I'll go to Google and I can type in the specific question like.
-
7:42
Let's take an example.
-
7:46
Excuse me, let's say, what's the best way to download images in Android?
-
7:54
You know, maybe I'm not familiar with some image downloading libraries I wanna know.
-
7:57
So sure enough there are some posts on stack over flow.
-
8:00
And if we click on the first one here and we scroll down to the answer.
-
8:04
And this person recommends, a library and we link to it.
-
8:08
And it's one called Universal Image Loader.
-
8:10
Okay, so this, looks like it will be useful for us.
-
8:12
It looks like it might be a good solution.
-
8:13
But then the next question I ask is, okay.
-
8:16
This is it's, it's pretty active.
-
8:18
We know that the last contribution was, was
-
8:20
about five days ago but, is there something better.
-
8:24
[BLANK_AUDIO]
-
8:27
So, then I remembered the most, the two
-
8:29
most important letters when researching open source libraries, versus.
-
8:34
And what I mean by that is, I will take the library name.
-
8:38
And then, start typing for Google Auto
-
8:40
Complete so this is Android Universal Image Loader,
-
8:46
and start typing a versus and sure enough
-
8:49
we get some alternatives because inevitable people will
-
8:52
compare the different options for us so unless
-
8:54
it's something brand new you can usually find.
-
8:57
Some good information, some good comparisons, maybe some benchmarks.
-
9:01
And this is useful as well because It's one thing to just find
-
9:06
and discover a library, but it's another to know that it's, useful for others.
-
9:10
That it's out there in the wild, that it's used
-
9:12
in apps and that other people have experience with it.
-
9:13
Because you wanna have something that's not gonna break on you.
-
9:15
You wanna, have something that maybe is in,
-
9:17
in use in popular apps with lots of downloads.
-
9:21
So in this example, we get a link to
-
9:24
another one that compared Picasso versus Universal Image Loader.
-
9:27
And if we look there, we can see, some additional information.
-
9:31
And then there's some additional recommendations as well.
-
9:34
Volley from Google and You are image view helper.
-
9:39
So the point is, you can kind of get lost in
-
9:41
the rabbit hole, looking through you know, looking for the best library.
-
9:45
But if you can, narrow it down to a few choices.
-
9:48
Get some information from the web, or maybe from some people you know.
-
9:50
Then you can go from there and try it out.
-
9:52
I'm gonna go back just a step here.
-
9:57
That's the other thing.
-
9:58
You know, asking real people for help.
-
10:00
So when I'm, again, when I'm, trying to find out something to do,
-
10:04
I'll ask some of the developers I work with, the Treehouse, for their experience.
-
10:08
We have a mobile team.
-
10:10
So they're a great resource there, on the cutting edge.
-
10:13
Working on our Treehouse Mobile Apps for Android and iOS.
-
10:15
And I can just ask them, like, hey, by the
-
10:17
way, have you been, you know, using anything for video streaming?
-
10:20
Which is something we do.
-
10:21
So, then we can get some information and they can point me in the right direction.
-
10:26
That's one of the big things I learned early on as a software developer was that.
-
10:31
There are so many people smarter than me and better than me at it.
-
10:34
So, I will try and make use of their knowledge rather than yeah,
-
10:38
reinvent the wheel again and try and figure things out on my own.
-
10:40
I will gladly accept, advice from somebody I know who's a reliable source.
-
10:45
All right, and the last one here is ask me.
-
10:47
On each slide I've got my Twitter handle.
-
10:49
So find me at Twitter.
-
10:50
Maybe Google Plus.
-
10:52
If you're a member of Treehouse, we have a Treehouse forum where we
-
10:56
discuss, you know, questions about the
-
10:58
material we're covering or anything in general.
-
10:59
So, I may not have an answer, but maybe I can help
-
11:02
you, get in touch with someone who does have an answer for you.
-
11:04
[SOUND].
-
11:10
Okay, and the other thing, So besides, you know, starting out
-
11:14
on something and, and trying to figure out you know, from scratch
-
11:19
what you wanna do, Another way to To stay in the
-
11:23
know is to, keep tabs on what is being released, what's available.
-
11:28
And it doesn't have to be a lot of effort.
-
11:30
The way I do it, you know whether or not this
-
11:32
would work for you is I follow certain people on Twitter
-
11:35
and I have a curated list for Android developers, and a
-
11:37
curated list for iOS developers, which if you're interested find me on.
-
11:40
Twitter and subscribe to those lists as well.
-
11:43
And it's things that you know, we'll talk about when
-
11:46
a new, specific library is released or, maybe, some helpful tips.
-
11:50
I've got two red, two newsletters [INAUDIBLE] there.
-
11:52
A couple different newsletters for both Android and iOS.
-
11:55
These are my two personal favorites.
-
11:58
Android Weekly.
-
11:58
That, both of them are weekly newsletters, but they just go out and curate the week's
-
12:03
latest posts, or sometimes new libraries, things that
-
12:06
are, of interest for Android and iOS development.
-
12:09
And what I'll do, I'll go through, check the newsletter.
-
12:12
I may not read anything in the newsletter, but, I'll at least bookmark things
-
12:15
that look interesting so I can either read about them later or use them later.
-
12:20
The last list here is to let others do the discovery work.
-
12:23
Again, letting, other people curate lists for you.
-
12:26
There's a couple web, websites listed here that I'll refer to
-
12:28
when I wanna find out, more about what might be available.
-
12:32
So the first one here is, called Android Arsenal, and this
-
12:35
is a pretty extensive list of, free libraries and tools for Android.
-
12:38
And if you scroll through, we can take
-
12:40
a look at, just everything from, you know, lower
-
12:43
level, lower level networking and cloud services to, controls
-
12:46
like date-pickers and animations and, et cetera for here.
-
12:50
And then the same thing for iOS is one called iOS Cosmos which
-
12:54
is a very similar, a lot of things about, graphics and networking, et cetera.
-
12:59
And then the last two I had listed were Cocoa Controls is one that's
-
13:05
specific for a UI controls for iOS and Active Wiki is another one that's similar
-
13:10
to the first two, that has a whole bunch of information about, both platforms about
-
13:14
libraries you can use and, and other
-
13:15
resources to help with, development on both platforms.
-
13:18
[NOISE] So of course when you think open source software you think of GitHub
-
13:23
which is, the most popular repository for open source libraries.
-
13:29
It's certainly not the only one.
-
13:30
But, that's another place I will go when I wanna
-
13:32
look for help, I may just want to look for.
-
13:35
Browse through and explore.
-
13:37
And here's a couple different ways you can, you can
-
13:39
look for just try and, find information that maybe help.
-
13:41
But you know whether you're, looking for a targeted search for something or
-
13:45
maybe just want to again, spend a few minutes getting to know what's available.
-
13:49
So if you go to, let's see.
-
13:53
Let's just go to GitHub.
-
13:55
And specifically if we go to explorer, they have
-
13:59
a bunch of different categories you can look through.
-
14:01
So if you're interested in something specific, you can come here.
-
14:04
But I like to go to, the trending, repositories as well.
-
14:07
And you can filter by languages.
-
14:10
So let's go down and let's filter by
-
14:16
Let's talk about Swift and see what the latest
-
14:19
things available are for, Apple's new programming language called Swift.
-
14:25
So here you can see you know, this is something that's brand new.
-
14:27
It's only been out for a few weeks, and already people are, creating
-
14:30
libraries and sharing them, creating sample projects
-
14:33
of how you wanna do certain things.
-
14:34
Here's one.
-
14:35
The second one here is called Swifter, it's a
-
14:36
Twitter framework for iOS and OS X written in swift.
-
14:41
So this is, you know, this is something you might wanna use in your app.
-
14:45
You know, if it's something that, that you need hep,
-
14:47
doing or maybe, again, example code that you can learn from.
-
14:50
So if you So we just wanna get up to speed with the new language.
-
14:53
You can come up to here and see some project that people are already running.
-
14:57
Download it, put it in Xcode and take a look of how they are things.
-
15:01
Sorry, I am getting a little, distracted by the, the volume next door.
-
15:06
okay, yeah, and then lastly, if you wanna search for any thing specific, so for
-
15:12
example were gonna cover How to consume rest based APIs in both Android and iOS.
-
15:18
So if we wanna look for iOS REST,
-
15:19
for example, let's just look in this repository.
-
15:23
I've got a switch to all repositories.
-
15:25
But we'll do the same thing iOS REST,
-
15:28
then we see some recommendations for some, REST-based
-
15:31
libraries for iOS, or the same thing for Android, if you want to go that route.
-
15:35
So all right, so that's enough about like, how to find things.
-
15:43
Again, moving on how to, once we find something,
-
15:47
how do we add it to our own projects.
-
15:49
And this is where for both platforms, it's so much easier than
-
15:52
it used to be, thanks to Girdle for Android and CocoaPods for iOS.
-
15:56
So I'm gonna start by talking about Android and we're
-
15:59
gonna look at Girdle and go through some, some popular
-
16:02
Android libraries and then we'll spend a little bit of
-
16:04
time on iOS and wrap up for questions at the end.
-
16:09
So just another show of hands, how many
-
16:12
of you are using Android Studio for Android development?
-
16:16
Okay.
-
16:17
And how many of you are using Eclipse still?
-
16:21
So, for Eclipse,
-
16:24
we would either, have to download a Ajax file or maybe
-
16:29
we could hook into Maven and pull in a library that way.
-
16:33
For Android studios we've got a new built system called gradle, and
-
16:36
it's a tool for automated project films, it needs to know everything
-
16:39
a project needs to be builter on and it also packages that
-
16:42
all up into and pulls it all together, downloads it from a.
-
16:46
It's a fantastic this is what im most excited about with Girdle
-
16:50
with Android studios specifically, It's just a one line One line you need
-
16:55
to add to your, build.girdle file, and you can pull in a specific
-
16:58
version of an open source library from a repository such as Maven Central.
-
17:03
And so many popular libraries are moving to this
-
17:07
format where it's so easy to just pull it in.
-
17:10
they're, in the repository or
-
17:15
To just download it, you can include from a
-
17:16
local repository to, I'm sorry, that's what I'm trying
-
17:21
to say.
-
17:22
All right.
-
17:22
So moving on, these are some of my, favorite libraries.
-
17:26
The first one here in the middle is called, Butter Knife.
-
17:29
And that's from developer, Jake Wharton, who works at Square.
-
17:33
We're gonna talk about Square a lot.
-
17:34
Square has some fantastic libraries available.
-
17:37
For open source for your apps.
-
17:39
Specifically for Android, they seem to have more for Android
-
17:42
than iOS, but there are some available for iOS as well.
-
17:45
In the upper right is a square library
-
17:46
called Picasso, and that's used for image loading.
-
17:49
The bottom right is one called list view animations, and it's
-
17:53
to do a whole bunch of different animations for list views.
-
17:56
So you know, list view is a very common element for Displaying data in Android.
-
18:03
And pardon me, there is a bunch of default animations you could tie in pretty easily.
-
18:11
Vertical movement, horizontal movement, having items slide up, having items fade
-
18:15
off as you, as they stroll toward the bottom on the list.
-
18:19
You know, I implemented some of that on my own and.
-
18:22
It's, it's ok but to be able to pull on a
-
18:24
library and just start using it is, again so much easier.
-
18:27
Bottom left here is called Retro Fit.
-
18:29
That is a, type safe rest client for Android and Java.
-
18:32
Were gonna walk through an example of that specifically but it's
-
18:36
a really nice, clean interface to use for consuming a REST API.
-
18:40
It uses some Java annotation's and it's a nice simple way to call a specific
-
18:46
API and then have that data translated for you into object models.
-
18:53
It uses, Retro fit uses library, another library called JSON which is JSON parsing.
-
18:59
And under the hood it converts your big
-
19:01
JSON document into specific Java object models which
-
19:05
is then makes it a lot easier to use in your app or persist your data.
-
19:09
The upper left is just example of a good UI library that's easy to tie into.
-
19:15
It isn't, this is a cards library, it's called CardsLib
-
19:18
and it's not particularly hard to implement your own, card interface.
-
19:22
It's just a box or rectangle, but this is
-
19:24
already done with a bunch of different formatting options and
-
19:26
again just to pull it in, it's a really
-
19:28
simple way to get some nice cards you can use.
-
19:34
[SOUND] Okay, so, I'm gonna start by looking at no, I got ahead of myself.
-
19:39
I'm gonna skip Picasso, and let's take a look at Butter Knife first.
-
19:42
So I've concocted an example here.
-
19:45
And this example is a little bit contrived just to, demonstrate.
-
19:50
But it is representative of a real world use of Butter Knife.
-
19:54
So here I've got a layout with a bunch of different controls on it.
-
19:58
I know this is cluttered.
-
19:59
It looks like an Android App from 2009.
-
20:01
But what we can do is reduce a lot of the boilerplate clode,
-
20:05
boilerplate code that we need to get access to those elements in the layout.
-
20:11
So just with the regular entered STK, we need to declare
-
20:15
all of our variables, call findViewById to get them from the layout.
-
20:20
And cast them to the appropriate view subtype
-
20:23
and then store them, maybe setting clis, setOnClickListener like
-
20:26
this with, this is an anonymous inner class here
-
20:29
for the OnClickListener which calls a method down here.
-
20:32
Using the magic of Butter Knife let's take a look at the website itself.
-
20:39
This is Butter Knife repository on GitHub.
-
20:42
And there's, it's a View Injection Library, so it's pretty lightweight.
-
20:47
So it's just a second about injections.
-
20:50
So this is a way to inject your views into the into your
-
20:56
activity and it's a lightweight version of something called Dependency Injection.
-
21:01
There's another open source library.
-
21:03
I'm not gonna talk about it specifically, but I wanna mention it just so, if
-
21:06
it is something that you need you can, you can look into it on your own.
-
21:10
But here the Butter Knife is like a Dagger, only infinitely less sharp.
-
21:15
Dagger is one of those Square Open
-
21:17
Source libraries that's used for Dependency Injection.
-
21:19
And that can be really useful if you wanna have for example
-
21:22
one thing I've used before is a versioning of clients of web services.
-
21:27
So I may have version one with an implementation and an interface,
-
21:32
and then I'll inject it into my activity where I need it.
-
21:35
But then if I need to roll up for version two, I can inject the
-
21:38
different version just with a simple change of the a line of code for Dagger.
-
21:44
But back to Butter Knife I'm gonna cheat here, just copy and paste and code.
-
21:49
But the idea is we can take all of
-
21:52
this boilerplate code and replace it with some injections.
-
21:57
And I'm gonna need to pull in the library as well.
-
22:02
I, I skipped the step here, but this is our new code.
-
22:07
I'm getting some errors because I haven't yet pulled Butter Knife into my project.
-
22:10
But it's super easy to do.
-
22:12
Thanks to Gradle.
-
22:13
So if we scroll down we can see here would be the, how
-
22:16
we wanna define a dependency using Maven, if we're doing this in Eclipse.
-
22:21
But with Gradle, we just add this one line to our file.
-
22:25
I'm gonna go to Android Studio.
-
22:27
And I've got the build.gradle file.
-
22:29
And I wanna point out that, yeah, in Android Studio if, if this is if
-
22:34
you haven't used it before an Android
-
22:36
Studio project can have multiple modules within it.
-
22:39
So I've got this project called Open Source Demo and inside is my app module.
-
22:43
And that's the actual app.
-
22:44
But you can have additional modules if you have other projects, maybe
-
22:47
a test project, or maybe a library project that you wanna reference.
-
22:51
So each project has its own Gradle file.
-
22:52
And you wanna make sure you put it in the right one.
-
22:54
There is a wrapper Gradle file here at the parent level, if I collapse this.
-
23:00
This one here is a top level build file and
-
23:02
this is to add configuration options for all your modules.
-
23:06
But I'm just working in the app module, so
-
23:07
I'm gonna close this one and go back in here.
-
23:11
And I, I already have line in here that we'll use in a
-
23:14
few minutes, but I'm gonna paste in that line I just copied from GitHub.
-
23:17
And this is how I am including version 5.1.0 of Butter Knife.
-
23:22
So now, sure enough, if I go back here, well, I still
-
23:26
have the errors because now I need to sync those changes to Gradle.
-
23:29
And I get a warning here it says Gradle files have changed.
-
23:32
So every time you make a change to Gradle we need to sync it.
-
23:37
So there's a link here for the button up here
-
23:40
with the little Gradle logo, sync project with Gradle files.
-
23:43
And the reason we need that is because the line that we added, the compile line
-
23:49
is saying that we want to pull in that library and use it in the project.
-
23:53
And our project doesn't have it yet.
-
23:54
So by syncing the Gradle files, Gradle runs, it
-
23:57
uses that reference to go down, pull that appropriate version.
-
24:00
And now it's in our project.
-
24:01
Now that the sink is complete, now I can go back to
-
24:03
main activity and take a look at how to use Butter Knife.
-
24:07
So, specifically here are the annotations I was talking about.
-
24:11
To inject the view we annotate it with @InjectView.
-
24:14
We pass in the ID, and then we just declare it up here.
-
24:17
So now we've taken seven lines that were in
-
24:20
the onCreate method, and gotten rid of those, and,
-
24:23
just by adding this, this InjectView in front of
-
24:25
each member variable in the class at the top.
-
24:27
It just makes the code a lot easier, a lot smaller more organized.
-
24:33
likewise, I really like this for the OnClickListeners.
-
24:35
You know everybody seems to have their own method for doing OnClickListeners or
-
24:39
anonymous inner classes when they're attaching listeners
-
24:42
or, or whatever to their UI elements.
-
24:46
This way you just inject it with the onClick attribute
-
24:50
and you specify the object that you are attaching it to.
-
24:53
And this is the method that gets run on the onClick.
-
24:56
And this one is just starting the new activity.
-
24:59
So there you can see our onCreate method is very clean and reduced.
-
25:03
The key here is to use the call ButterKnife.inject.
-
25:07
You pass in the current context, and that
-
25:09
has to happen before the call to setContentView.
-
25:12
So that's why it's between the super call and setContentView.
-
25:17
But that takes care of it.
-
25:19
That wires everything up.
-
25:20
And now we can reference our layout elements in code, just like anything else.
-
25:25
So I can say m hello world label, and set the text equal to goodbye instead.
-
25:31
Oops, a little bit of Objective C stuck, snuck in there.
-
25:36
Okay.
-
25:37
[SOUND] All right.
-
25:44
So now I'm gonna go back to Picasso.
-
25:47
Here we go.
-
25:50
And this is
-
25:54
a very convenient image loading library.
-
25:56
Without Picasso, downloading images in Android is cumbersome.
-
26:02
You have to get the image URL, create an AsyncTask, which is a little bit complex.
-
26:07
There are different methods you need to override and make sure
-
26:10
you call it from the right place store the result in
-
26:12
bitmap, and then you're responsible for caching that image yourself, if
-
26:15
you wanna cache it to avoid a network call each time.
-
26:18
Well, all of that is handled automatically with Picasso.
-
26:20
You include the library using one line in Gradle just like
-
26:24
we saw, and then with the image URL you add one line.
-
26:28
Now, it's configurable, there's different ways you can load the ImageView but as
-
26:32
we'll see with this example, you just load it into an existing ImageView.
-
26:35
We don't need to replace any of the ImageView element itself.
-
26:39
We can use existing ImageViews.
-
26:41
It's, it's built right on top of that.
-
26:44
So I'm gonna go to the Picasso GitHub page.
-
26:50
oh, and that's right.
-
26:52
This one doesn't have that specific Gradle line
-
26:56
that we need, but it's the same pattern.
-
26:59
All of the Square Open Source libraries
-
27:01
are available through made in Central like this.
-
27:04
So we can go back to our build file and.
-
27:08
[BLANK_AUDIO]
-
27:12
I'm gonna add another line to Import Picasso.
-
27:16
And pardon me for just a second, I got the note here on my phone.
-
27:20
Here we go.
-
27:21
So we're compiling com.squareup.picasso, and we're
-
27:29
on version [SOUND] com Picasso, version 2.3.2.
-
27:36
Okay?
-
27:36
And I'm gonna sync these changes with Gradle again, using this button up here.
-
27:43
And I get my messages down at the bottom, Gradle's executing, and hit complete.
-
27:48
Okay.
-
27:48
So now I go into main activity
-
27:52
and I'm going to replace my image.
-
27:54
Here I've got an image of one time machine, a TARDIS.
-
27:58
So, instead, let's replace it with image of another time machine.
-
28:00
Let's use this DeLorean here instead.
-
28:04
So, back in my activity.
-
28:08
Pardon me.
-
28:10
We're gonna use the line just like we saw on the slide.
-
28:13
We used the Picasso library.
-
28:16
And then, we, the first thing we passed in was the context.
-
28:18
And, it has this nice method signature.
-
28:22
So with the context, it's very it, it reads very clearly, like English.
-
28:27
We're saying, okay, with this context, load this URL.
-
28:31
And I'm just gonna paste in that URL I grabbed.
-
28:34
And load it where?
-
28:34
Load it into our ImageView.
-
28:37
And I already have an ImageView here call it M Tardis ImageView.
-
28:43
And if we do that, then it's going to
-
28:47
take care of loading that image asynchronously in the background.
-
28:50
And then it's gonna cache it on the device for us as
-
28:52
well, so that we don't have to make that network call again.
-
28:55
So let's just, I think if we run this,
-
28:59
we should be able to see [SOUND] the ImageView.
-
29:05
Now I am using just a side note how
-
29:08
many of you are using Genymotion in your area development?
-
29:14
Now, I see only one hand.
-
29:14
Okay.
-
29:15
So [APPLAUSE] if nothing else out of this talk,
-
29:18
please check out Genymotion, it is a fantastic resource.
-
29:21
It's so much better than the stock emulator.
-
29:27
And they have a bunch of different images of, like real devices available.
-
29:31
So if you wanna test higher app runs on a Nexus or a Samsung device or
-
29:35
an HTC device, you can download different images
-
29:38
and then run them as devices on your machine.
-
29:42
That looks like, I'm not sure.
-
29:48
I don't want to spend too much time troubleshooting.
-
29:51
I was just gonna run it to see.
-
29:53
But all right, well let's skip ahead, we'll come back to that if we need to.
-
29:57
So we're gonna keep going through, a couple more libraries as well.
-
30:05
oh, skip ahead here.
-
30:07
Pardon me for just a second.
-
30:09
I'm gonna go back here.
-
30:11
The next one I wanted to, to demonstrate was Retrofit.
-
30:14
This is that REST client for Android.
-
30:16
And that's the line that was already in our build file,
-
30:21
so if we go there and take a look at build.Gradle.
-
30:25
Here's the line to get version 1.6 of Retrofit.
-
30:30
And to use it
-
30:31
[BLANK_AUDIO]
-
30:35
we need to declare.
-
30:37
Here I've got a services package.
-
30:39
So we've got an interface here, which is the, for service that we're consuming.
-
30:43
So I'm gonna use a REST API from forecast.io.
-
30:47
And let's take a quick look at what is, what that looks like.
-
30:51
So this is just a free API to use and it's, it's pretty complex JSON.
-
30:55
The reason I wanted to use it was it's an example of
-
30:58
a complex payload with all these nested objects and arrays of objects.
-
31:04
so, if we scroll through this is just current,
-
31:08
current weather conditions and a longer forecast, et cetera.
-
31:12
So the format of the request is you pass
-
31:15
in your key and then the latitude and longitude.
-
31:19
So if we get back to the code we see it has an
-
31:22
annotation, this is a getMethod and also you can use post as well.
-
31:26
And then you give the, the format of your API
-
31:29
call, which is what we just saw key, latitude, longitude.
-
31:34
And then we map the parameters here.
-
31:36
We have the, a method called get forecast async and it maps
-
31:40
these key lat and long parameters to those items from the paths.
-
31:44
So you can see the, the curly
-
31:46
braces around the parameter names match down here.
-
31:49
And that uses the callback mechanism because
-
31:51
once again this is an asynchronous call.
-
31:52
It's gonna make the weather forecast call and come back,
-
31:56
call this callback and then we can handle the response.
-
31:59
So, we have this is just the interface itself, but the next class is the client.
-
32:03
This is the implementation of the interface and here we've got the base URL
-
32:07
we need, the key, and this is what where the real work is done.
-
32:13
We use the Retrofit REST adapter class.
-
32:17
We create a new one using the builder.
-
32:19
We set the end points.
-
32:20
And build, this is an optional logging parameter, which if we
-
32:26
saw down there you can see quite a lot of information from the Retrofit call.
-
32:32
And then we set we create it for the forecast service class.
-
32:37
That's the interface that we just looked at.
-
32:40
And then we've got a method here to get the forecast
-
32:42
data where we pass in the latitude, longitude, and a callback.
-
32:45
So then, to call it from our activity and I know I'm, I'm kind
-
32:48
of going through this fast, but if you want to take a look at
-
32:51
this code and use it as an, an example I will share these slides
-
32:54
and make the repo available on GitHub for you to look at as well.
-
32:58
Cuz for me again, best way to learn is
-
33:00
by looking at an example that's, you know, how
-
33:01
I practice Retrofit was looking at examples apps that
-
33:04
used it and reading a little bit about the documentation.
-
33:07
So here in main activity
-
33:13
actually I forgot I put it in a different activity.
-
33:14
So I've got a second activity called Forecast Activity.
-
33:17
And all I wanna do is show current temperature in a label here in the middle.
-
33:24
So here we use our forecast client app.
-
33:26
It's a singleton instance of just the forecast service.
-
33:31
And then we call the get forecast data.
-
33:34
This is latitude and longitude of Las Vegas.
-
33:38
And then we pass in the callback.
-
33:39
And this is a Retrofit callback.
-
33:42
And it has a forecast object.
-
33:47
So before we, we'll come back to that in just one second.
-
33:49
The, the format of the callback is simply success or failure.
-
33:53
So if it comes back with a success, we get the object model to match.
-
33:57
And we get a Retrofit response, so we can investigate it as well.
-
34:00
Otherwise, we get the error and we can handle the error if we need to.
-
34:04
So about that model.
-
34:05
We had that complex JSON and we need our Java representations of it.
-
34:13
Now if we wanted to hand-code our
-
34:15
Java representations it would be pretty tedious.
-
34:18
If I go to the model's package here and I take a look at all of this.
-
34:21
I did not code this by hand, thank God.
-
34:24
You know, it's just a bunch of getters
-
34:26
and setters and member variables, and things like that.
-
34:29
What I used was a generator and there are
-
34:32
some helpful JSON generators for both Android and iOS.
-
34:36
They may not be perfect, but at least it's going to save you 90,
-
34:40
95% of your work because it's gonna do a bunch of boilerplate stuff for you.
-
34:43
Then you can go in and make a few modifications.
-
34:45
So, for the Java example, I use this one here called jason gen.
-
34:50
And you pass in the URL that you're looking at, and give it a few parameters.
-
34:54
So give it a package name and your base object class name.
-
34:58
And it generates a zip file for you.
-
35:00
And that's pretty much what I have here.
-
35:02
I had all these classes generated and it worked almost perfectly out of the box.
-
35:07
The only thing that was missing was I headed to add, I had to add
-
35:13
somewhere, I had to add data for the list elements.
-
35:18
I forget, I forget where specifically but point
-
35:21
was, it saved me a whole bunch of work.
-
35:22
It was about five minutes of work, as opposed to however
-
35:25
long that would have taken to hand code all of those.
-
35:27
And there's a similar tools for iOS that we'll look at
-
35:30
in just a moment when we get to the iOS portion.
-
35:33
So up, before I come back here.
-
35:40
Sorry I'm jumping around a little bit trying to remember the rest of these tabs.
-
35:45
I have these laid out to show.
-
35:46
I don't have a specific example of the CardsLib or the ListViewAnimations.
-
35:51
Just in the interest of time, we're already running a little bit long.
-
35:56
But this is the Square Open Source page.
-
35:57
Again, Square has a bunch of libraries for different uses in Android and elsewhere.
-
36:03
But there's a lot for Android.
-
36:05
And there's a few IOS and then Java and JavaScript as well.
-
36:12
The cards library is just, here's more examples of
-
36:16
the different kind of card formats you can use.
-
36:18
So, you know, it looks like what you might
-
36:19
find in Google Now or in the Google Play Store.
-
36:21
And it's just really easy to pull in and adapt for your own collection of use.
-
36:26
And then, lastly, ListViewAnimations this
-
36:32
is this page doesn't actually have a demonstration but if you go to the Play
-
36:36
Store demo, there is a video that has a bunch
-
36:39
of examples of what the ListView can do for you.
-
36:42
And then, again, this is just, you know, you pull
-
36:45
in the ListView and adapt your data and then you
-
36:48
can make use of these canned animations, which look pretty
-
36:50
slick and would be a lot of work on your own.
-
36:57
Okay.
-
36:57
So the last thing here for Android I
-
36:59
wanna mention is a project called Android Bootstrap.
-
37:02
And this is by a developer named Donn
-
37:04
Felker, and it's an Android Studio project that
-
37:06
has a bunch of popular third party libraries
-
37:10
built into it already as an example project.
-
37:12
So you can see the list of the different things here.
-
37:15
And it's pretty up to date too.
-
37:17
This an older version had more backwards
-
37:19
compatible things like ActionBarSherlock or some other ones.
-
37:22
But things have been updated and it shows examples of how to use Fragments.
-
37:26
You see Retrofit is mentioned there, and GSON.
-
37:30
Robotium is is a good testing tool for
-
37:32
Android and it uses the back in, Parse.com.
-
37:36
I wanted to talk about Parse independently.
-
37:38
It's not exactly an Open Source product, but it's just so useful.
-
37:41
But for more information, to see an example of how
-
37:44
that's used, you could take a look at this app.
-
37:46
And it's, again it's just another example of looking at somebody
-
37:49
else's code to find out how you could do something better.
-
37:54
Okay.
-
37:54
So moving down to iOS we talked a lot about Gradle as a dependency manager.
-
38:00
And we saw how Gradle can pull in things automatically into our project.
-
38:04
iOS has the same thing.
-
38:05
It's been around longer.
-
38:06
It's called CocoaPods.
-
38:08
And this is again where I was saying that it, before CocoaPods, integrating
-
38:13
into an iOS project could be a real headache depending on your library.
-
38:16
With CocoaPods it's like Ruby Gems, if you're familiar with that concept.
-
38:22
It requires Ruby.
-
38:23
It's, it's built with Ruby.
-
38:24
So when you install it you know, when you install
-
38:26
it on your machine, you have to install it using Ruby.
-
38:30
And then it installs and updates third party libraries.
-
38:33
And one of the key differences is that when
-
38:36
you use CocoaPods it creates something called an Xcode workspace.
-
38:40
And you need to work with your project in the
-
38:42
framework of that Xcode workspace, instead of the Xcode project.
-
38:46
If that doesn't make sense, it's okay.
-
38:47
We're gonna look at an example here in just a second.
-
38:50
If you wanna get started with CocoaPods, these
-
38:53
are a blog post and a video of Treehouse.
-
38:56
They're both give a nice overview of how to get started with CocoaPods and
-
39:00
pull in a library to, to get familiar with, with how to do it.
-
39:04
It walks through the set up on how to install
-
39:06
CocoaPods and then set it up for your Xcode project.
-
39:14
Okay.
-
39:14
So we saw a couple different highlights of Android open source libraries.
-
39:19
I've got a few listed here as well for iOS.
-
39:21
The first one here in the upper left is called AFNetworking and it's
-
39:25
a very popular networking library to handle whatever kind of network you need.
-
39:30
You want a lot of open source tools
-
39:32
are built on top of AFNetworking, such as RestKit.
-
39:36
RestKit is the iOS version of Retrofit that we saw for consuming our Rest APIs.
-
39:42
And RestKit is built on top of AFNetworking.
-
39:44
The other two are just examples of smaller things that can be really helpful.
-
39:48
TPKeyboardAvoiding it, how many people have either used this or had to program on
-
39:55
keyboard that has elements on the screen that scroll out of the way by themselves.
-
40:01
Show of hands, anybody?
-
40:03
Okay, well if you need to, this is so much easier than
-
40:06
trying to do it yourself, because in iOS when you've got a
-
40:10
page of controls that need user input, you need to be responsible
-
40:15
for making sure they get out of the way of the soft keyboard.
-
40:19
And the Apple documentation has.
-
40:23
Guidelines on how you need to do
-
40:24
that yourself, but it involves following a certain
-
40:27
protocol, implementing a bunch of methods, and setting
-
40:29
up your scroll to be a different way.
-
40:30
It's a real headache.
-
40:31
So instead, what you do is you use this
-
40:34
TPKeyboardAvoiding library, you pull in a scroll, a special
-
40:38
scrollview that has all this code built in for
-
40:40
you, so then you just drop your controls in there.
-
40:43
And it's all handled automatically.
-
40:45
And it's again, one of those libraries that's very popular.
-
40:48
It's up-to-date, so you know you're getting a reliable quality
-
40:52
solution, rather than trying to do it on your own.
-
40:55
The SSKeychain, I'm not going to show you an example
-
40:57
of, but it's specifically to interact with the iOS Keychain.
-
41:00
It's for both iOS and Mac.
-
41:02
But so, it's a way to access user credentials.
-
41:05
So if you wanna store your user credentials in the iOS or Mac key chain.
-
41:10
You could reference them using this open source library.
-
41:15
so, okay.
-
41:16
Why REST kits?
-
41:17
Specifically, that was, remember when we looked at GitHub?
-
41:20
I, I said iOS REST, and RestKit was the first.
-
41:23
Response the first result that came up.
-
41:27
It's comparable to Retrofit and it just makes
-
41:29
for easy REST API calls, and it has that
-
41:33
kind of JSON to Objective-C object mapping that we
-
41:36
saw but it's not quite as clean as Retrofit.
-
41:40
Retrofit was all handled kind of under the hood by the JSON Library.
-
41:45
RestKit, will do the mapping for us, but we
-
41:47
need to be a little more explicit in our mapping.
-
41:49
And you'll see what I mean here in just a moment with an example.
-
41:52
Okay.
-
41:53
So, actually, pardon me.
-
41:59
I've got the project open, but I wanted to show where
-
42:02
you would differentiate between the Xcode workspace, and the Xcode project.
-
42:07
So if I go to
-
42:10
development > open source demo IOS, A regular Xcode project, when
-
42:16
you create a new one, gives you this Xcode project file,
-
42:20
When you go through the CocoaPods installation or when you rather
-
42:25
when you use it to add a library to your project.
-
42:28
The first time you do it, you're going to run
-
42:30
a command that will generate an Xcode workspace file instead.
-
42:34
And this is what you use to then open your project.
-
42:36
If you open the Xcode project itself, then it won't have
-
42:39
the necessary components from CocoaPods to pull in your third party library.
-
42:43
So then you just have to switch over to using the Xcode workspace after that.
-
42:49
So how does CocoaPods know what to include in your project?
-
42:54
So we saw the one line that we added in Gradle.
-
42:56
CocoaPods uses something called a pod file, and the format
-
43:01
is a little bit different but the idea is the same.
-
43:04
We add one line for each pod we want to include.
-
43:07
And they, CocoaPods will go out to repository.
-
43:10
And it will check and match the, the pod specs for the library one.
-
43:16
And it will take care of downloading the necessary components, and
-
43:20
adding all the additional frameworks or other pieces you might need.
-
43:23
And that's where it really helps because it automates that
-
43:27
process where you need to set flags, and include frameworks.
-
43:30
And make other changes to your project that are easy to mess up.
-
43:33
So this line here includes RestKit.
-
43:36
And if we go to CocoaPods' website you can search the library of available CocoaPods.
-
43:43
So here, if I search for RestKit specifically, I
-
43:47
can read up about how to include the RestKit library.
-
43:49
Or if I just want that line for the latest version, I can copy
-
43:52
that specific line here to my clip board and paste it into my pod file.
-
43:56
Once we have the pod file we need to go into
-
44:00
the command line, and do a, something called a pod install.
-
44:03
That's the command that generates our Xcode workspace.
-
44:07
And if we wanna update this, so let's say
-
44:09
a new version of RestKit comes out, maybe it's 0.24.
-
44:13
We would specify the change in our pod file,
-
44:16
because right now we're tied to that version 0.23.
-
44:21
If we update our version, we then need to run a separate command called pod update.
-
44:24
We need to go back and manually update our libraries.
-
44:28
And again, the reason that's not automatic is in
-
44:29
case an update would break something from your project.
-
44:31
It's up to you to see if you want to take the latest update and pull it in.
-
44:36
And it's the same thing with Gradle as well.
-
44:41
So let's go back to this project here and I want
-
44:43
to take a look at an example of how to use
-
44:46
RestKit, and you'll see here that it's it's a little bit
-
44:50
verbose compared to Retrofit which is a common complaint of Objective-C.
-
44:55
But with a good working example, its easy fairly easy
-
45:00
to extend it or change it for your own APIs.
-
45:07
So this is consuming the same forecast API and we see the same kind of path here with
-
45:11
the forecast and the parameters, the key is the
-
45:13
first one, latitude and longitude, and we're plugging them in.
-
45:17
Then we use this element to create something called a response descriptor.
-
45:25
I don't want to spend too much time on the inner workings of how, how to
-
45:28
setup a RestKit, but we see that we need to create our own mapping of the objects.
-
45:35
And then we set the method, the path pattern is what we saw
-
45:39
up here the, the API path and then the status post we're looking for.
-
45:44
And this is again like Retrofit, it's going to make an asynchronous call.
-
45:48
It's gonna have a callback mechanism in Objective-C,
-
45:50
it's the blocks that we see down here.
-
45:52
So once we have everything registered.
-
45:54
And I'm gonna talk about the mapping here in just a second.
-
45:57
We set up the request and we make it so make the call down here, operation start.
-
46:04
But we have to tell it what to do when we get a response from the API.
-
46:07
And that's where the blocks come in.
-
46:09
We've got a success block and a failure block.
-
46:13
And on success here, we're just going to parse through the
-
46:15
forecast and update the display and on the failure, its just login.
-
46:22
so, once again were going to need a object
-
46:25
models in Objective-C to represent that complex JSON we saw.
-
46:29
This was the, JSON itself here, and these are the, object models here.
-
46:39
This is similar to what we saw in Android.
-
46:41
And again, I didn't hand-code these.
-
46:43
These were generated by a tool.
-
46:45
So there's a couple different tools available.
-
46:48
I used specifically one called.
-
46:53
Where is it?
-
46:55
I use this one call JSON Accelerator.
-
46:57
It's a Mac app, you downloaded, you past in your JSON and
-
47:00
generate you model, and then you can copy them into your project.
-
47:04
There's another one that I didn't try out but looks promising.
-
47:07
It's called RestKit Generate, it's again from GitHub.
-
47:10
So, I, I looked for you know, I didn't
-
47:12
know what might be available to generate model's for RestKit
-
47:16
so I went on Google and I went on
-
47:17
GitHub and I looked for you know RestKit generate models.
-
47:21
Or generate JSON model's for RestKit.
-
47:23
Things like that and ended up with these two different tools.
-
47:26
This is our Ruby-based tool, I think, yeah and it just does the same thing.
-
47:31
It'll generate the model classes that we need.
-
47:34
And we copied them into our project and then if they're available for the mapping.
-
47:37
Now I saved mapping for the end because this was the cumbersome part of RestKit.
-
47:43
But this is, no matter what you're doing,
-
47:45
whether you're doing an API call on your own
-
47:47
or using the library, you're going to have to
-
47:50
map the response, the JSON response to your objects.
-
47:56
Go back to my code and back to the view control.
-
48:01
So here we map the specific JSON object
-
48:07
names to the properties of the objects.
-
48:13
And it does like a one to one mapping.
-
48:16
We, there are different ways you can map it.
-
48:17
But this because I'm using the same names in the JSON as
-
48:20
the object models, we just need to specify where they are coming from.
-
48:25
And then with this is in place
-
48:26
[COUGH] we also need to establish parent-child relationships.
-
48:31
Or nested objects as well.
-
48:34
So, for example, a forecast object includes an alerts object.
-
48:39
And down here at the bottom, we add those relationships.
-
48:43
So, forecast mapping has the forecast object has an hourly object.
-
48:47
It has a daily object.
-
48:49
And this allows RestKit to go through and make sure
-
48:51
that everything gets parsed correctly into the objects we need.
-
48:57
Once that's in place, then we just call the method like this, and the blocks, oh
-
49:05
yeah, and the blocks, for the response we
-
49:07
define down there, this code is a little cluttered.
-
49:09
I apologize, it's not very organized.
-
49:11
But the blocks for success and failure will then handle the response for us.
-
49:16
okay, we talked about the RestKit model specifically, already.
-
49:23
Got a few minutes to go, which leaves me
-
49:27
a minute here to talk about CocoaPods and Swift.
-
49:33
Does, everybody familiar with, when I, I
-
49:35
keep talking about Swift, assuming everybody knows what
-
49:37
it is but, a show of hands if you do know what Swift programming language is.
-
49:41
Okay, so most people.
-
49:43
This is the future of iOS development.
-
49:46
Apple has been working Swift for a couple of years and they announced it at WWDC a
-
49:51
couple weeks ago and it won't, the language itself is available to
-
49:58
talk about and look at but you need to have Xcode 6 beta to work
-
50:03
with it, and to get Xcode 6 beta, you need to be an Apple developer.
-
50:06
So that's a long way of saying you need to
-
50:07
be in the Apple developer program to really play around Swift.
-
50:11
But we can talk about it and we can look at
-
50:12
some examples but one of the first questions of course was,
-
50:17
if I'm doing a Swift project, can I use CocoaPods, can
-
50:20
I use an existing library, and can I use a Swift library?
-
50:25
And the answer to both questions is yes.
-
50:27
So it's a definitive yes for the first if you wanna
-
50:33
use an Objective-C library, such as RestKit in a Swift project.
-
50:37
You need to do something called, use a bridging header.
-
50:40
And that's a bridge from Swift to Objective-C.
-
50:43
And I just included an example.
-
50:45
There's a couple different articles on how to do that,
-
50:47
but you basically set the header file that tells the
-
50:50
Objective-C components you need and it puts them in place
-
50:53
so that you're Swift project knows how to find them.
-
50:56
Because if you try to import an Objective-C file
-
50:59
into Swift you're going to get a compiler error.
-
51:03
And then sepo, specifically, to use CocoaPods to include a Swift
-
51:06
project, a Swift open source project into your own Swift app.
-
51:10
That is supposedly in the works.
-
51:12
I haven't checked the very latest information to
-
51:15
see if, you know, where, where that is.
-
51:17
But that should, supposedly be done in time for when Swift is publicly available.
-
51:23
>> If you're bridging to an Objective-C library in Swift, would you need to, how
-
51:28
you you use the Objective-C library in Swift,
-
51:31
how would the, how would the syntax call?
-
51:34
>> Yeah, so, from what I understand, let's,
-
51:36
they give an example here in this article.
-
51:40
So then once you pull it in, this, this just walks through how to set it up.
-
51:44
so, you're ready to use Objective-C in your project.
-
51:51
And this is SVProgress HUD so-
-
51:58
[BLANK_AUDIO]
-
52:03
I'm not exactly sure how the call is made it.
-
52:07
>> Yeah, that was what I was trying to figure out.
-
52:09
>> Yeah, because it's the, this is the Swift method format, but-
-
52:13
>> If you write Swift and know stuff is translated
-
52:16
across the bridge, or you have to put it in Objective-C?
-
52:20
>> Yeah, I'm not sure.
-
52:20
I haven't tried this out myself yet.
-
52:23
Good question, though.
-
52:23
[BLANK_AUDIO]
-
52:26
It's a good segue because we're on to final questions.
-
52:30
That's all I had specific to cover.
-
52:33
But if you have any questions now please ask.
-
52:36
If you think of anything afterwards find me
-
52:38
on Twitter and, and follow up there as well.
-
52:41
Any other questions while we're in here?
-
52:45
No?
-
52:45
Cool.
-
52:45
All right thank you so much for listening I've got two free shirts if anybody wants.
-
52:50
There's a small and a large just come up and, and ask me.
-
52:53
And first come, first serve, you're welcome to them.
-
52:55
Once again that stuff from Treehouse is in the back
-
52:58
if you want to give us a look check out teamtreehouse.com.
-
53:01
There's cards for a free trial, and stickers and things and there's, we have
-
53:04
more information about both Android and iOS,
-
53:06
CocoaPods and Gradle and, good stuff like that.
-
53:11
All right.
-
53:11
Thanks a lot.
-
53:12
[APPLAUSE]
You need to sign up for Treehouse in order to download course files.
Sign up