Pattern matching in Swift

One of the best explanations about pattern matching in swift I've seen so far. Insta-bookmark.

Content hugging and compression resistance

: ~40 sec read

Even though the names might sound self-explanatory, I never really understood how they work. But I finally found a proper explanation about them:

A strong hugging priority limits the view from growing much larger than the content it presents. A weak priority may allow a view to stretch and isolate its content among a sea of padding. Compression resistance describes how a view attempts to maintain its minimum intrinsic content size.

I'm considering to buy the book too, while I'm at it.

Subscriber Share for streaming music

: ~1 min read

I recently saw this medium post linked on The Loop, and at first I thought "sure, this is a major issue, but, on the other hand, it seems pretty fair to be paid by the number of plays, that's what streaming means; I can't see any another way", but eventually I reached the part where he offers a solution; and I think it's perfect:

The premise behind Subscriber Share is simple: the only artists that should receive your money are the artists you listen to. Subscriber Share simply divides up your $7 ($10 per month, -30% service fees) based […]


Continue reading →

Breaking Cocoa

This was a fun Saturday morning read. And very interesting.

Swift and enums #2

: ~55 seconds read

Continuing where we left off last time, is another little trick I like to use with enums:

func collectionView(collectionView: UICollectionView, layout: UICollectionViewLayout, referenceSizeForFooterInSection section: NSInteger) -> CGSize {
  if .Products == Section(rawValue: section) && contidionOne && !conditionTwo {
    return CGSize(width: 10, height: 20)
  }
  else if .ShippingDetails == Section(rawValue: section) && anotherCondition {
    return CGSize(width: 10, height: 40)
  }
  return CGSize.zeroSize
}

I think this […]


Continue reading →

Search vulnerability

: ~1 min read

I recently wrote that I added a visual representation for when a search is performed, by autocompleting the search field with the search query. Everything appeared to work as expected.

Some time ago I added Tinfoil Heroku addon and never saw any security problems. I even thought I will never see one. But I started seeing a couple about Cross-Site Scripting in HTML tag. I went to their dashboard, clicked on reproduce the attack, it took me to my website, with a search performed, the search query was autocompleted, as expected, but a tag was also injected in the […]


Continue reading →

iOS good practices

: ~25 sec read

This is a really nice resource, I'd suggest on at least reading it, if not bookmarking. Even seasoned developers will find useful stuff inside, but if you are a junior, or have one in your team, it's definitely a must-read.

It goes hand-in-hand with this awesome resource list.

Swift and enums #1

: ~1 min read

This will only work for enums that are Ints, start from 0, and increment by 1 - for example tableView / collectionView sections, but I think it's a nice little trick, that I always use:

private enum Section: Int {
  case Products = 0,
  ShippingDetails,
  PaymentDetails,
  Total,
  NumberOfSections
}

Now you can do the following:

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
  return Section.NumberOfSections.rawValue
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
  let cell: UICollectionViewCell

  // […]

Continue reading →

SASS' Mixins

: ~40 sec read

I recently saw a nice example of Mixins for SASS. So I went ahead and created a few, since I really dig them:

@mixin responsive_width($width) {
  @media screen and (max-width: $width) { @content; }
}
@include responsive_width(475px) {
  // Custom styles for width <= 475px
}

@mixin light_bottom_border($size) {
  border-bottom: $size solid $light_gray;
}

blockquote {
  @include light_bottom_border(5px);
  @include light_top_border(5px);
}

article {
  @include light_bottom_border(1px);
}

I also unified most of the website's colors with […]


Continue reading →

Improving the search

: ~40 sec read

I wanted a visual representation and helper for the user when a search is performed on the site. So I thought about autocompleting the searched term in the search field. At first I tried with jQuery:

var query = decodeURIComponent(location.search)
  .split("=")[1]
  .replace(/[\+]/g, " ");
$('input.search').val(query);
$('input.banner-search').val(query);

But this had a small delay and the slight inconvenience of having to replace + with a space, and to decode […]


Continue reading →