I recently added some tests to LTHRadioButton, and I gave mirroring a try, something I always wanted to do. What's mirroring? As Apple puts it, it's a representation of the sub-structure and optional "display style" of any arbitrary subject instance.
Working with Core Data is getting easier and easier, but there are a couple of improvements I'd like to talk about, and I'd like to start with the auto-generated, generic NSFetchRequest. It's a step in the right direction, but the problem is that trying to use it without explicitly declaring its type won't work:
class ProductModel: NSManagedObject { }let request = ProductModel.fetchRequest() // <- Ambiguous use of fetchRequest().let request1: NSFetchRequest<ProductModel> = ProductModel.fetchRequest() // <- Works properly.
Update, Oct 10, 2017: It has been solved, all of this is now redundant. Yay!
I was in need of a radio button recently, and it had to be designed like a Google Material Design radio button. Nothing too fancy, but I wanted to spice it up a little bit, by adding a nice animation. The idea was to:
start with a gray border, with an empty center
fill the center inwards with a blue color
slightly increase its width
as it reaches max width, release a wave outwards
reduce the center's width back to normal
color the gray border blue, as the wave passes "over" it
fade out the wave and reduce its width as it moves out
Say we have a composed string that looks like this:
let date = "22 July, 2017"let value = "€ 148"let quantity = 5let string = "\(quantity) of your items, in value of \(value), have been delivered on \(date)."// 5 of your items, in value of € 148, have been delivered on 22 July, 2017.
It would be nice to emphasize the important bits, and the usual approach would be to create an NSMutableAttributedString, and to add the required attributes:
Let's say we have a controller that can fetch some data. What would this imply? A loading spinner, the fetching of the data and the update of the UI. We can create a protocol for this, maybe Fetchable:
protocol Fetchable { func showSpinner() func fetchData() func updateUI()}[...]class Controller: UIViewController, Fetchable { // showSpinner, fetchData and updateUI are required.}
But showing a spinner and updating the UI could be useful by themselves, so we could extract those into separate protocols:
I recently had this problem: at the start of the app there's a call to fetch some reference data, on which other calls depend, but it shouldn't hinder the app launch itself, nor anything else that doesn't depend on it. So, after several approaches, I decided to use DispatchGroups.
First, a struct to abstract a DispatchQueue and a DispatchGroup:
struct Queue { let group = DispatchGroup() let queue: DispatchQueue init(label: String) { queue = DispatchQueue(label: label) }}
This class should have a way to add a closure to the queue, that won't require waiting, basically just abstracting async(execute:):
Last post in the series is about creating a new post. This wasn't really needed, since the whole point of having my blog in Dropbox was to use any markdown editor I desire, save the file, run the sync command, and have it live, but for the sake of learning, I went ahead and added this feature too.
For Dropbox handling I chose a pretty small library, node-dropbox. To use it, I went in Dropbox's developer dashboard and created an access token (instead of using secrets and keys) and saved that in my .env. Then onto the helper:
Last time we created a basic database handling functionality, but it was clear we can improve it: posts aren't the only ones that need fetching, and requiring the dbconfig file everywhere (and configuring the object) will become cumbersome. So, a first step would be to create specialized DbConfig objects: