Operator Overloading & Custom Operators in Swift

Operator Overloading
Every once in a while we will end up in situations where we would need the functionality of existing operators e.g. +, -, *, /, etc for our own classes or structures. Lets say you were creating a game called “Cube Collector”, wherein, you start with one small cube in a universe filled with cubes of all sizes. You have to look for new cubes and every time you find a cube, your cube size is increased by adding the newly found cube to existing cube.

Our cube definition could be

Continue reading…

Understanding Enums using Swift

Enums are a way to represent a “type” of values which are all related together. Lets say you had an application called MyFamily, which showed you different members in your family and their relationship to you every time you opened the application. Now, the relationship of every member in your family to you could only be one of the few values. This relationship could be represented by a “FamilyRelationshipType” using an enum as follows. FamilyRelationshipType is essentially a new data type.

Continue reading…

Listen, I mean seriously LISTEN!

I remember back when I was in school, whenever the professor asked a question, a series of hands went up and everybody was very eager to share their answer or their opinions. While I totally agree that speaking up takes a certain amount of courage and also requires or develops the ability to communicate clearly, what I am not sure about is whether it encourages us to “listen to what others have to say”

One of the very important qualities for any leader is Listening. There are several articles on this topic, so many that, whenever we encounter advice about listening, we take it for granted. We assume that we are good listeners and we already have it nailed. But seriously, are we that good? I find it to be a constant battle for me.

Continue reading…

Swift – SequenceType & GeneratorType

We are quite used to looping through collections such as arrays / dictionaries using for-in

For e.g.

Now, lets say the details of library are encapsulated. i.e. The UI layer will receive a library object from the data layer and, all we know is that the library object is a collection that supports for-in looping just like an array.

Continue reading…

What is your Greatest Weakness?

A question that we are all asked in an interview is “What is your greatest weakness”. I remember early on in my career somebody advising me that I should use this question as an opportunity to present a strength but wrap it up as a weakness. One of the answers that I bet a lot of us used at one point or the other, I know I have used it, is; “I am a stickler for perfection, I sometimes take additional time to make things perfect. I am working on this aspect though. I am trying to finish my work a few days ahead of my deadline to have some extra time if I need to make things perfect.” Or, some bullshit along those lines. But seriously, how many of us sit down and think what our weaknesses really are?

Continue reading…

5 Important Attributes to Evaluate a Job

Every once in a while we all sit and contemplate whether we should stay at our current job or find something new. The reasons could be several. Next time you’re in this situation, I would recommend making a list of all the attributes that are important to you in any work place. Below are the attributes that are important to me and I believe should be important to all engineers.

Learn – Personally, I think that we should always be looking for opportunities to learn. Learning is one of those intrinsic motivations I look for in any job. If you are just starting a new job then you should learn how to perform your job, learn how things are done in this new environment, learn how to effectively work with new colleagues, etc. Once you’re comfortable with these then your should seek additional challenges that provide you with an opportunity to learn something new – learn to handle new & bigger projects, learn how to collaborate with multiple teams, learn how to manage and mentor new hires, etc.  In fact, everybody should treat their jobs as a sort of higher educational institution because your current job prepares you for your future. One can get a good sense for learning opportunities by asking interviewers about what is it that they have learned during their tenure with the company.

Continue reading…

Objective-C Copy vs Strong

I was recently working on putting together iOS code review guidelines with my colleagues at work. One of the guidelines I had proposed was  –  “Use copy instead of strong when declaring properties of objects, which have mutable variants e.g. NSString, NSArray, etc”. A colleague expressed concerns that using copy would be a hit on the performance.

In my view, one of the main reasons to use copy attribute was to preserve encapsulation. But, I was curious about the performance concerns myself. All I remembered was reading that Apple optimizes the copy attribute for you but had no data. I put together a sample program and here are some of the results:

Continue reading…