0:00:00- Welcome to Under the Radar,
0:00:01a show about independent iOS app development.
0:00:04I'm Mark Warmant.
0:00:05- And I'm David Smith.
0:00:06Under the Radar is never longer than 30 minutes,
0:00:08so let's get started.
0:00:10So today we wanted to talk a little bit about
0:00:13what I kind of think about as like sidecar data,
0:00:17things that kind of, data that you need to often ship
0:00:21with your app or provide to your app
0:00:23that supports its function, but isn't necessarily
0:00:26like the main content of the app.
0:00:29And what's interesting about this,
0:00:31and we have a couple of recent things that both you and I
0:00:34have been working through with this, Marco,
0:00:35where there's lots and lots of different ways
0:00:38that you can actually package up data like this
0:00:41to include it in your app.
0:00:43You can include it all the way from the extreme
0:00:45of like including it in code to shipping configuration files
0:00:50or shipping a database with it,
0:00:53preloading like a core data database.
0:00:55You can download it from the internet as JSON or PLIST,
0:00:59you can download it from the internet as a database file.
0:01:02You can bundle it with, I think Apple even has
0:01:05a distribution system where you can add assets
0:01:08that are downloaded on demand.
0:01:09Like there is a tremendous variety of things
0:01:11that you can do with this.
0:01:12- I forgot about that entire system.
0:01:14- I think it's primarily used for games, I think.
0:01:17I think mostly it's used for situations like that.
0:01:19But anyway, we'll get into why you might want to use that.
0:01:22But it's a situation that I think happens often,
0:01:26and there's all these weird trade-offs that you have
0:01:27with speed, performance, first run experience,
0:01:31time and downloading, but it happens more often
0:01:33than you will.
0:01:35And I think this first came to mind, I think,
0:01:37is something that is probably worth you explaining
0:01:39for how you implemented instant search
0:01:42in Overcast, the most latest update,
0:01:45which I think was a really clever system
0:01:47and approach to taking, sort of solving this kind
0:01:49of a problem.
0:01:50- Yeah, sure.
0:01:51And I went into it in detail on ATP,
0:01:53so I won't go into too far detail here,
0:01:54but basically Overcast has a new instant search feature
0:01:59which downloads about once a week.
0:02:01It downloads a search index from my servers
0:02:04and stores it locally, and then when you perform a search,
0:02:07it first hits that before it gets the results back
0:02:10from the server, and then it puts the server results
0:02:12below those results.
0:02:13So you can start typing, you can immediately get results
0:02:16from that local index while you're waiting
0:02:18for the network request of the server for the other results.
0:02:21And I think so of many of these decisions
0:02:25and trade-offs with this, because one thing I considered
0:02:28was obviously it has to be very small.
0:02:31The index can't be like 100 megs.
0:02:33That's a bit much to force people to download
0:02:35in the background once a week without even them knowing
0:02:38about it or without asking them or without providing
0:02:39any controls for it.
0:02:40And it didn't seem like an important enough feature
0:02:42to have a preference to turn it off or have it off
0:02:44by default or anything like that.
0:02:46But, so the file's small, it's about three and a half megs
0:02:51right now, and I said once a week downloads.
0:02:54But I also thought, should I bundle one with the app?
0:02:58Should I have in the app bundle your first search index
0:03:01and then whenever the app gets a chance,
0:03:03it downloads whatever's current from the internet.
0:03:05And I thought, that's not great, because then I'm forcing
0:03:09everyone for the next month or month and a half
0:03:13or two months until I do my next app update,
0:03:15I'm forcing them to download this data that will,
0:03:18one week in, be out of date.
0:03:20And that seemed like a bad idea to put in my app bundle.
0:03:24But if it's something that didn't change very often,
0:03:27I absolutely would have put it in there.
0:03:29No question I would have put it in the app bundle.
0:03:31And I might in the future build in a very small default one
0:03:34just to have some kind of results there for the most
0:03:38popular searches or something like that.
0:03:40But that was one consideration right there of like,
0:03:43do you bundle it into the app bundle directly
0:03:46or do you download it after installation?
0:03:48And I think that one is a very easy one for me.
0:03:52I think you can bundle it in only if it's either
0:03:57super critical to the app's functionality,
0:03:59so that that way if someone launches the app
0:04:01and it hasn't downloaded it yet, they can still achieve
0:04:04what they need to achieve in the app.
0:04:05So if it's super critical functionality,
0:04:07it needs to be in the app bundle.
0:04:09Or if it's something that very rarely ever changes,
0:04:12that you can just update it when you issue app updates
0:04:15and it's no big deal to have that kind of frequency
0:04:17of updates, then it makes sense.
0:04:19Build them into the app bundle and avoid
0:04:21all the other concerns.
0:04:23Like I think if it's a feature that very few people use,
0:04:26who cares?
0:04:27As long as it isn't like a massive file, still bundle it in.
0:04:30But if it's something that needs to be updated
0:04:31on a regular basis, that's when you look at downloads.
0:04:34- Yeah and I think too with that,
0:04:36I've in a variety of different apps,
0:04:38I've done different versions of this.
0:04:40And a lot of times what I find too,
0:04:43there's something nice about the app
0:04:46being self-contained that you can avoid a situation
0:04:51where someone downloads the app when they have connectivity
0:04:55and then their first launch,
0:04:57if their first launch of the app requires connectivity
0:04:59to do something, it's kind of a bad experience.
0:05:03And so too I think it's always,
0:05:05even if that initial cache may be something
0:05:08that will get invalidated or will be immediately updated
0:05:11when they launch the app, it's something
0:05:13that I've done a couple times where I'm trying
0:05:15to make sure that there's almost this basic usefulness
0:05:20that the app can have right out of that initial download.
0:05:24That you don't assume that well,
0:05:25if they had, obviously they had internet connectivity
0:05:28when they downloaded the app,
0:05:29of course they're gonna have it
0:05:30when the first time they launch it.
0:05:31But I don't think you can necessarily rely on that.
0:05:33And obviously depending on what the app is,
0:05:35that's more or less relevant.
0:05:37If it's a, like my first app that I ever actually shipped
0:05:40into the App Store, this is over 10 years ago now,
0:05:43was a reference app that showed you
0:05:45like cost of living per diem stuff for travelers.
0:05:50And for that one, it's like the app is completely useless
0:05:52if it doesn't have its database.
0:05:53And that first version I shipped it,
0:05:55just had like a plist file as its database,
0:05:57which subsequently got upgraded to a SQLite database
0:06:00that was shipped with the bundle.
0:06:01But it was one of those things where I wanted to make sure
0:06:04that as long as you got all of the app, it worked.
0:06:08And that was all you had to,
0:06:10all the connectivity that was required.
0:06:12And also I think it's something that always sticks
0:06:15in the back of my mind, is that one nice thing
0:06:18about shipping it with the bundle is that you are not,
0:06:23it doesn't require you to be maintaining something else
0:06:26in order for the app to continue to function.
0:06:29So as long as they have access to that app bundle,
0:06:33they will be able to use the app in some ways.
0:06:35If at some point you lose interest in the app,
0:06:38it kind of starts to fall away
0:06:39and you turn off the web server
0:06:41where all of the content was being served from
0:06:44or that cost becomes unsustainable,
0:06:47it's kind of nice in almost like
0:06:50a software preservation perspective or whatever,
0:06:52that even several years later,
0:06:54as long as Apple is still a thing
0:06:57that is serving assets from the App Store,
0:06:59someone could download the app or re-download it
0:07:01from their purchased history and it could still work.
0:07:05So that's just another thing that's kind of nice
0:07:06about bundling it directly into the app itself.
0:07:09- Yeah, exactly.
0:07:10Because one of the reasons why I did instant search
0:07:13was that when I have server issues like I did
0:07:17over the holidays, I did periods I talked about,
0:07:20if I have server issues, search is critical to a podcast app
0:07:23because it's the first thing people do to add podcasts
0:07:27and it's a very frequent thing to search for new ones
0:07:30and I wanted to make sure that was always gonna be fast
0:07:32and even though if my servers are totally down,
0:07:35you can't subscribe to a new podcast,
0:07:37so I'm not totally immune here,
0:07:39but I at least have a level of protection here.
0:07:42If there's spotty connectivity or server issues here,
0:07:47I'm giving them a better experience
0:07:48than I otherwise would have.
0:07:50- Yeah, and I think in general,
0:07:52that's a great use for this type of,
0:07:54it's essentially what a lot of this kind of data becomes
0:07:59is essentially it's advanced caching.
0:08:02It's different, it's a more robust version of caching
0:08:07that you might do ahead of time,
0:08:09so you can call it pre-warmed caches,
0:08:12but it's things that you could eventually download
0:08:16from the internet potentially
0:08:17or that may be part of the normal use of the app
0:08:19is that in your case, with search,
0:08:21most of their results eventually are gonna be coming
0:08:23from the web server, but as fast as that might be,
0:08:28as optimized as you might make it,
0:08:30it's still never gonna be as fast as in memory or on device.
0:08:35Those are situations that are always gonna be better
0:08:38and it's a dramatic difference in user experience
0:08:41to have it locally there by pre-warming those caches.
0:08:44I mean, you can sort of get around this sometimes
0:08:46where as soon as the app launches,
0:08:49it goes off and starts pre-warming its caches or things
0:08:52so that by the time someone goes to the search tree
0:08:54and you may have already gotten some of this and so on,
0:08:57but it's never gonna be,
0:08:59it's always a tricky balance to know the timing of that
0:09:03and the resources of that and having that be ready
0:09:06exactly when you want it to be there.
0:09:08We are sponsored this week by Linode.
0:09:10With Linode, you can instantly deploy and manage
0:09:13an SSD server in the Linode cloud
0:09:15and you can get a server running in just seconds
0:09:17with your choice of Linux distro,
0:09:19resources and node location.
0:09:22Linode serves their customers with the help of 10 data
0:09:25centers around the globe and they're about to add more.
0:09:28Mumbai, India and Toronto, Canada will both have
0:09:31data centers by 2020.
0:09:32Linode also features native SSD storage
0:09:35on all of their servers.
0:09:36They have a 40 gigabit network behind it all
0:09:39and they use Intel Xeon E5 CPUs.
0:09:41This means you have amazing, fast hardware and networking
0:09:45to serve your customers as fast as possible.
0:09:48And you don't have to worry about overspending
0:09:50because Linode has designed their pricing tiers
0:09:52to feature hourly billing with the added bonus
0:09:54of a monthly cap on all plans and add-on services
0:09:58including backup services and node balancers.
0:10:00Linode has fantastic pricing options to suit everyone.
0:10:04The plans start at one gig of RAM for just $5 a month
0:10:07and then for high memory plans starting with 16 gigs of RAM.
0:10:10And Linode has a special offer for our listeners.
0:10:12Listeners of the show can go to linode.com/radar
0:10:15and use promo code radar2019 to get $20
0:10:19towards any Linode plan.
0:10:21Once again, it's linode.com/radar,
0:10:23promo code radar2019 to get $20 towards a plan.
0:10:27So on the one gig of RAM plan,
0:10:28that could be four months for free.
0:10:30And with a seven day money back guarantee,
0:10:33you have nothing to lose.
0:10:33So give Linode a try today.
0:10:35Linode.com/radar, promo code radar2019.
0:10:38Thank you so much to Linode for hosting everything
0:10:41I run on the internet and for sponsoring
0:10:44our show and Relay FM.
0:10:45- So what I think would be interesting
0:10:48to kind of walk through now is the spectrum of ways
0:10:53that you can ship code or ship data with your app.
0:10:57And this is, there's a tremendous variety
0:10:59and each of them has different trade-offs
0:11:01that I think are interesting to talk about.
0:11:02And I'll start with the most like, I don't even know,
0:11:05like bare metal silly version,
0:11:07which is you can ship data in code.
0:11:11And this is something that you almost certainly
0:11:13you are doing to some degree, like some amount,
0:11:15obviously there's a certain amount of data
0:11:17in your application, irrespective of almost anything
0:11:21in terms of even you could think about
0:11:22like localizable strings is a form of data
0:11:25that is being shipped with your app.
0:11:27But even if it isn't like quite that straightforward
0:11:30degree, like you could just have an array of static strings
0:11:34that are like a standard list that is often shown
0:11:37in your application that you have to choose from.
0:11:38Like for example, in my workout app, Workouts++,
0:11:41I have, you know, there's a bunch of data
0:11:44that is associated with each of the different workout types.
0:11:47You know, you walking, running, doing yoga, whatever it is.
0:11:51And a lot of the information about those,
0:11:53I just store in code.
0:11:55Like I have, you know, sort of lookup tables and things
0:11:58that are just dictionaries that are just static values
0:12:01that I ship in the application.
0:12:02And this approach sort of works well in some ways
0:12:06that it's very straightforward.
0:12:10You know, it doesn't scale well.
0:12:11It doesn't work if you, it works fine
0:12:13for like 20 or 30 values.
0:12:15It doesn't scale well if you have 20 or 30,000 values.
0:12:18You know, it's not something that you would necessarily
0:12:20wanna put a huge amount of things into,
0:12:23but can be really straightforward.
0:12:24And it certainly is something that I think we all do
0:12:27at some point is there's a certain amount of data
0:12:30that is just in the code.
0:12:32The downside of course is that it's in the code.
0:12:34It's not something that you can update
0:12:36unless you update the application.
0:12:38You're tying your data versioning to your code versioning.
0:12:41So like in terms of from a version management perspective,
0:12:43you're tying those two things together,
0:12:45which can not be a great situation.
0:12:49If you are doing this, you know,
0:12:52if you're pushing the limits of this,
0:12:53like Xcode will start to get really grumpy
0:12:55if you are actually like, you know, having, you know,
0:12:58the source code files that have, you know,
0:13:01several thousand lines that are all just string literals.
0:13:03Like you could do that, but it probably is gonna make
0:13:06your life uncomfortable even just from a day-to-day use
0:13:10and you know, compile times and opening the file perspective.
0:13:13Like it's, or the thing that often will, you know,
0:13:16bring source editors to their needs
0:13:17is like trying to do syntax coloring
0:13:19on these big massive string files.
0:13:22Like you'll just see, like you'll actually watch
0:13:24the coloring move down the page sometimes.
0:13:26(laughing)
0:13:27Like if you ever see that, you've gone too far on this.
0:13:30Like it's appropriate at the small level
0:13:33and it's super helpful because it's super performant.
0:13:35Like these are strings directly in like the code space
0:13:38of the application, like it's right there.
0:13:41Don't go too crazy with that,
0:13:42but it's certainly something that is available to you
0:13:46as a tool.
0:13:48And I think like the next one up from that,
0:13:50I think is probably where you start to get into
0:13:53serialized data structures that are not shipped in your code
0:13:58but are functionally like loaded into memory.
0:14:01So this is where I start to think of like
0:14:03if you have a P list or a JSON blob or something like that
0:14:07that you are storing, you know,
0:14:08either shipping with the app like we were talking about
0:14:11or downloading from the internet, you could go either way.
0:14:13But you know, you have a data structure
0:14:15that you're functionally gonna be like, you know,
0:14:18NS array, you know, in it with contents from UI
0:14:23URL kind of a thing.
0:14:24And you're going to just immediately slurp it up into memory
0:14:27and you'll have an in-memory dictionary
0:14:29or an in-memory array.
0:14:31And that's how you're gonna access that data.
0:14:34And this I find is something that I probably use most often.
0:14:39It's very flexible in terms of it's nice that you can,
0:14:44the data is external to your code.
0:14:46So you're not creating that dependency.
0:14:48It's, you know, Xcode is perfectly happy
0:14:50to have a resource file in its bundle
0:14:51that could be bigger than you'd actually want to edit there.
0:14:55It's reasonably performant.
0:14:57It works pretty well for a medium size,
0:14:59like small to medium sized data sets.
0:15:02And like I'm actually in the process right now.
0:15:05I mean, this is relevant for me
0:15:06because I'm working on pedometer plus plus
0:15:08on a time zone feature.
0:15:09And I need to have a list of, you know,
0:15:12popular cities and their time zones.
0:15:14So you can choose time zones from cities.
0:15:17And it's one of those things where it falls
0:15:19into that kind of middle ground
0:15:20where ultimately I'm gonna have maybe like 1,800 cities
0:15:25or so, like not so many that I feel like I need to go full,
0:15:28like have, you know, have a database
0:15:31that I can, you know, make SQL queries against.
0:15:33It's not that many, but it's big enough
0:15:36that I need to externalize the data somehow.
0:15:38And so right now, what I've been doing
0:15:40that seems to work pretty well
0:15:41is I'm just putting it into a plist file.
0:15:43And I just load that plist file in whenever the user
0:15:47happens to want to do this search.
0:15:49You know, it's slightly big in memory, but not crazy.
0:15:51And it's an operation that doesn't happen very often.
0:15:54So it isn't something that I'm super worried about,
0:15:57but you can just take that, you know,
0:15:59it's you're functionally just taking a data structure
0:16:01that you would normally have in memory
0:16:03and you can write it to disk and you can read it from disk.
0:16:05And, you know, you can do the same thing.
0:16:06You can tell a dictionary or an array and say like,
0:16:08you know, save, you know, write to file
0:16:11and it'll, you know, essentially put out a binary plist
0:16:13that you can then really, you know, reload back in.
0:16:18Or you can go even more extreme and you can use like
0:16:20the archiving APIs in, you know, in iOS
0:16:24where you can take an arbitrary data structure
0:16:27and be, you know, be rewriting that to disk
0:16:30and reading that in and then it starts to get
0:16:31a little bit more advanced and a bit more complicated
0:16:33and you should start starting to think,
0:16:35maybe I want to do this in a database
0:16:36where I'm not the one having to like manage
0:16:39all this really sort of nuanced data management stuff.
0:16:42But that certainly is the most extreme version of this
0:16:45is when you start using like the keyed archiving
0:16:47and secure archiving and all of those types of things.
0:16:51- Yeah, and there's a number of trade-offs
0:16:52you have to consider when you're picking between these.
0:16:54So like one of the biggest ones that I think
0:16:57would bite a lot of people kind of unexpectedly
0:16:59is the true memory footprint of having
0:17:03one of these simpler solutions, like a plist file
0:17:05or a JSON file because not only do you have to consider
0:17:09that like the entire, like usually if you're parsing
0:17:12a plist or a JSON file, usually that means
0:17:15the entire contents of that file
0:17:17are going to be loaded into memory.
0:17:19It also usually means that they're going to be decoded
0:17:22into different data structures that will end up using
0:17:26more memory in actual like usage RAM
0:17:30in their native structures like NS dictionary,
0:17:31NS array and everything.
0:17:33That'll use more memory than the size of the file.
0:17:36So you really have to be careful if you're doing this
0:17:38to test, like to actually monitor, like load up your app,
0:17:42watch the memory usage meter in whatever developer tool
0:17:45that you're running it in, you know, instruments
0:17:47or the Xcode window like in the little like now running
0:17:49screen that shows the CPU memory and stuff.
0:17:51Watch what happens to the memory usage
0:17:52when you load that data in.
0:17:54It will probably go up by more than you think it will.
0:17:57And you know, so if it's like you know, one meg,
0:18:02who cares, right?
0:18:03If it's 20 megs or 50 megs or 100 megs,
0:18:06you should start caring.
0:18:07Like at that point, you have a much bigger footprint
0:18:10than you probably should and that can cause problems
0:18:13in things like getting your app kicked out of memory,
0:18:16having it maybe crash on older phones that don't want
0:18:18to give you that much memory or can't give you
0:18:19that much memory.
0:18:20You could start having potential just battery usage issues
0:18:23of just having lots of RAM thrashing in and out
0:18:26and everything so it's important to make sure
0:18:29that you're not gonna blow your memory budget
0:18:32by having just one big file.
0:18:34You can start doing a little more custom things
0:18:36like this is one of the things I hate about JSON
0:18:39is that there doesn't seem to be what in XML
0:18:43people used to call a SACS parser,
0:18:45which was basically a streaming parser that would like
0:18:48call your callbacks on begin tags, end tags,
0:18:51got tag contents, et cetera.
0:18:53And so you could basically stream an XML file
0:18:55through memory without ever loading the whole thing
0:18:57into memory.
0:18:58I don't know of any JSON streaming parsers,
0:19:01but anyway, you can kind of fake it,
0:19:03you can like do some custom work where like you have
0:19:05a file that you write in certain blocks and you have
0:19:08like custom ways of reading it so that each block
0:19:10is itself a smaller piece of JSON or whatever,
0:19:12that's pretty complicated.
0:19:13I think once you're getting to those kind of levels,
0:19:16you should be looking at it at just a database.
0:19:18And this is how I do my search index.
0:19:20I mentioned earlier my search index,
0:19:21my offline search index is about three and a half megs
0:19:24most of the time and so it is literally a SQLite file.
0:19:29That's all.
0:19:29And one of the great things about this as opposed
0:19:32to things like binary P list and everything,
0:19:34not only do you not have to load the whole thing
0:19:35into memory and everything, but it's also,
0:19:37it's easier to have server side tools that generate it
0:19:40because if you're not using an Apple platform,
0:19:44the tools for reading and writing Apple's P list format
0:19:46are weak at best and so if you can have something
0:19:50like SQLite or JSON, you can write server side,
0:19:54that's great.
0:19:55What's great about SQLite is that it is incredibly
0:19:58well optimized, like it's kind of shocking how fast
0:20:03SQLite is, like it shouldn't be as amazing as it is.
0:20:07There's a reason why it is very widespread.
0:20:10Even Apple uses it for a lot of OS stuff.
0:20:12A lot of stuff built into Mac OS and iOS is based
0:20:15on SQLite, including core data.
0:20:17There's very much reasons for that.
0:20:19Anyway, so just shipping around a SQLite file,
0:20:22I think is a very, very good solution.
0:20:24The only major downside to it is it is kind of overkill
0:20:28if you are dealing with a data set that's pretty small.
0:20:32So if you have like under 1,000 items in your data set,
0:20:36you probably don't need SQLite for that.
0:20:39And the other thing I would say is it does involve
0:20:41some code overhead that you have to write,
0:20:45you have to link to the SQLite dilib and you have to
0:20:49actually have SQLite calling functions and you might,
0:20:52you could use a wrapper library.
0:20:54My preferred one for that is FMDB by our friend Gus Mueller
0:20:58and I use it in Overcast, I use it as much as I can,
0:21:01it's wonderful.
0:21:02You can also use the direct C API but it's a little
0:21:05cumbersome so it's not necessarily the best option
0:21:08for most people but that's about the only downside
0:21:11is like yeah, you have to code in support for SQLite.
0:21:14Other than that, I strongly recommend it because one
0:21:16of the other things, like we're talking about memory costs
0:21:19and size considerations but another thing to consider
0:21:22is look up speed and if your data set is small,
0:21:25you know computers are fast, it's not gonna matter,
0:21:27you can scan through all of them just by doing like a dumb
0:21:30string match, is this the right title?
0:21:31No, is this the right title?
0:21:32No, just scan through the whole set.
0:21:35But when your set becomes large enough where that could
0:21:39be a problem, you actually will see significant gains
0:21:42by having some kind of index structure like having
0:21:45a binary tree lookup or something, that's what databases
0:21:48do so if you create an index on like a title column,
0:21:52you can have way faster lookups of potentially massive
0:21:56data sets and you can look them up basically instantly.
0:21:59Like I'm, again, like look at Overcast Instant Search,
0:22:02I am shocked how quickly it's able to pull up results
0:22:06from a, you know, three and a half meg database that has
0:22:10tens of thousands of entries in it and it's able to pull up
0:22:13entries from a single keystroke basically immediately.
0:22:16Like it basically takes no time at all.
0:22:18And so if you have a big enough data set where that matters,
0:22:23you should really just go straight to a database
0:22:25at that point.
0:22:26- Yeah, and I think too there's two other things that I
0:22:28think come to mind with databases that'll make them
0:22:30really nice and I think the first one too is just to point
0:22:33out that you can use core data to create the database
0:22:38that you're going to ultimately ship with the app to
0:22:44and when you set up your core data context, you can just
0:22:49point that to a file.
0:22:50Like I think you need to copy it out of your bundle
0:22:52so it's in your, you know, so it's in a read write place
0:22:55in the data, in user space but that's a trick that I've used
0:22:59a few times where I have a version of the app that has
0:23:04a build that builds the, essentially in my case it was
0:23:07pre-caching a bunch of data about the various audio books
0:23:11in the audio book catalog for my audio book app.
0:23:14And it builds this core data database and then I just take
0:23:18the SQLite file that is underlying core data, put that in
0:23:22my bundle, when you first load up I copy that SQLite file
0:23:26into user space but then I just point core data to it
0:23:29and I get all of the affordances and the nicenses that
0:23:32core data gives you.
0:23:33You don't have to necessarily go down to the low level
0:23:36of using actual SQLite calls for managing it.
0:23:40It can be all kind of managed from that top level
0:23:42in the same way that you might say if you had a cache
0:23:46that you were going to be storing data in with core data,
0:23:48if that was something that you wanted to do, you would be
0:23:51doing that through your application.
0:23:53You can kind of still do that and have that file
0:23:56underlying it that's ultimately all core data is.
0:23:58So that's just something to keep in mind.
0:24:00And I think too, the other big advantage that you get
0:24:03whenever you have this kind of sidecar data in a database
0:24:07as opposed to in a file, it becomes much easier and more
0:24:11of a robust situation if you want to make changes to it.
0:24:15So that if you make it non-static.
0:24:16So if for example this is a cache where you are caching
0:24:21results or prefetching results and you're making
0:24:26it so that when the user does something it's instantaneous
0:24:28but then it's going to fetch some more results later,
0:24:31you could potentially just start adding those into this
0:24:33database file and maybe it starts off being a small file
0:24:37but over time it grows.
0:24:39And that's what this does well with.
0:24:42A database is great for that kind of thing.
0:24:44You just insert more data into it and it sort of scales nice
0:24:48and with a controlled usage pattern and performant
0:24:51sort of expectation there.
0:24:52Whereas if you were doing something with a,
0:24:55you know, with a P list say, you could, you know,
0:24:59add in, you read the P list into memory,
0:25:01you add some items to it, you could write it back out
0:25:04to memory but that starts to very quickly start to get
0:25:07really cumbersome and awkward and you have to deal
0:25:09with all kinds of consistency issues.
0:25:11What happens if, you know, the app was killed
0:25:13halfway through a write and you can write it atomically
0:25:16but hopefully it works and like a lot of these things
0:25:18are completely handled by SQLite.
0:25:23That it's doing all the clever checkpointing
0:25:25and management and consistency stuff that it's nice
0:25:29to not have to think about.
0:25:30So those are two things that I definitely want to mention
0:25:32with databases where they can be super flexible
0:25:35and also probably third is just to keep in mind
0:25:37that it's entirely reasonable and not even like,
0:25:40there's not a tremendous overhead for this
0:25:42to access multiple databases from your application
0:25:45concurrently which I think is I guess what you do
0:25:47in Overcast, right, where you have a search database
0:25:49that is doing this stuff and you also have
0:25:51the actual app database that is actually storing,
0:25:55you know, the user's information.
0:25:56And it's perfectly reasonable to do that
0:25:58and you could have as many of them as made sense
0:26:00and that could really give you cleanliness
0:26:03in terms of both your code and the actual creation
0:26:06of this data that they could be coming
0:26:07from different systems.
0:26:08You don't have to sort of throw it all into one
0:26:10giant database that you then have to manage.
0:26:12- Oh yeah, exactly.
0:26:14One other thing I wanted to touch on too is
0:26:15if you're building in like some kind of source of data,
0:26:20go back and listen to the episode that I talked about
0:26:23building my original search feature in Overcast
0:26:25and like how to build a search engine
0:26:26'cause I wanted to emphasize a point that I went over there
0:26:29which is like make sure you're sourcing your data
0:26:32in a responsible way.
0:26:33You have to see like if you're getting, for example,
0:26:36you know, you're talking about getting a list of cities
0:26:38and what time zone they're in.
0:26:40You have to make sure if you get this list,
0:26:41first of all, like are you legally allowed to copy this
0:26:44and put it into your app or is it copyrighted
0:26:46and you know, you could get yourself into trouble.
0:26:48Make sure that you have the legal right
0:26:50to embed this in your app.
0:26:52Make sure that it is from a good source,
0:26:55that you probably have like a good and complete
0:26:58and correct data set and make sure you have some way
0:27:01to update it easily in the future if it's the kind of,
0:27:04if it's data where like it has the nature
0:27:06where it will change over time.
0:27:08So like, you know, a list of major cities
0:27:10probably doesn't need to change that frequently
0:27:11but you probably should update it like at least once a year
0:27:15and so like, you know, it's worth like considering
0:27:17how often will this data need to be updated.
0:27:19Can I build some kind of automated system for that?
0:27:21Do I have any kind of reliable source
0:27:24for where I can get this list?
0:27:25And as much as possible, automate that
0:27:28and build that in up front so you don't have to like
0:27:31get caught off guard later.
0:27:33- Yeah, and I think too along those lines
0:27:34is also just making sure that, yeah, that you are,
0:27:38you understand where the data comes from.
0:27:39I think it's with certain types of things,
0:27:41it's easy to kind of just, oh, I found this thing on the,
0:27:44I found this thing on the internet and I downloaded it
0:27:46and it seems like it has the right data in it.
0:27:48And it's like, if both from a copyright perspective
0:27:51that could be problematic but even just from a,
0:27:54in six months if you need to update it
0:27:56or people start reporting problems or whatever it is,
0:27:59like having a sense of the origin of the data
0:28:01and where it's coming from, if it's, you know,
0:28:03a lot of these like say you're working with something
0:28:05that's using like OpenStreetMap status as set
0:28:08or something like that, like at least you know,
0:28:10okay, where it's coming from and hopefully you have
0:28:12some kind of script that can download the data
0:28:14that you're interested in and process it
0:28:16and then generate the thing that you need
0:28:17for your application.
0:28:19Like having a end-to-end solution there
0:28:22where it isn't just like you found somebody who did
0:28:25have a script that pulled in the data and did something
0:28:28and then you're bundling that, like you're just setting
0:28:31yourself up for pain in the future where something's
0:28:34gonna change, some requirement's gonna change
0:28:36or you're gonna want to add a field to that
0:28:38and then suddenly it's, rather than being
0:28:40a relatively straightforward thing,
0:28:41it's this big massive project.
0:28:43So yeah, it's like be very thoughtful about
0:28:45where you're getting this kind of data
0:28:48and just being aware that it should be something
0:28:51that you have good understanding of,
0:28:54that in general you want to be sure about
0:28:55that you're sending any data that you're including
0:28:58in your application, like you're taking responsibility
0:29:01for it, so if there is anything that in it
0:29:03that is potentially controversial or questionable,
0:29:06you have to be aware of it, don't just like take it
0:29:08and then blindly use it.
0:29:09- Yeah, and make sure what you're using is legal.
0:29:12- Yes.
0:29:13- All right, well thank you everybody for listening
0:29:15and we will talk to you next week.
0:29:17- Bye.