The swift class extension you’ll want to include in all your projects

Here is one of my favorite extension I created for Array. Very useful shortcut when you use abstraction ( as you should ) and you want to create an array from another one.

Description

Instantiate an Array of type A with an another array of type ( or protocol ) B and fills it with elements from B that can be cast to A.

Code

Example

Screen Shot 2016-06-08 at 2.57.33 PM

You could always use .filter but it would take way more lines.  I often use it to get a specific subview in my view hierarchy.  Here’s the link to the playground file.

MABDev.ArrayExtension.playground

That’s it for today folks !  See you soon. MAB.

 

UIImage, prepareForReuse and multiple reload data

So you are working on a UICollectionView and you have to call “reloadData()” a few times in a row because you have data coming in. I know it would be better to insert items or at least reload the section but sometimes for good or bad reasons, like custom layout manager and iOS 9, it’s not always possible. And it’s not the point here anyway.  The point is I recently had a problem with my UIImageView flashing like crazy overtime I call “reloadData()” .  I found out in your “prepareForReuse()” implementation, rather than setting you imageView.image = nil you’re better off doing imageView.hidden = true and unhide it later when you need to set it again in “cellForItemAtIndexPath”.

MyCell.swift

Not much but I thought it could interest some of you guys. Cheers !

Edit: It might not be the best solution after all. It behave poorly in bad / slow network conditions. 

Hello World

Hello word !  First blog post ever.  Never heard of me huh ?  No worries, so does 99.99% of the population.  We’ll get to know each other I’m pretty sure of it.  All you need to know for now is that this blog is about my new company “MAB Développement Mobile inc.” but most importantly about iOS and Swift.  I want to use this place as a repository of all those priceless snippets of code and good tricks you get to learn but too often lose and forget.  It’s also a forum so I’m counting on you to put your shoulder to the wheel.  I also want to have fun doing it and reading your comments, because that’s what life is about… fun.