What is Mutability in regards to iOS and Objective-C?

Mutability refers to the ability to mutate or change.  Immutable refers to lacking the ability to mutate or change.  These are my notes from the apple developer website.  I rewrite my notes because it helps me to retain the information I am learning and use most often with my line of work as a mobile developer.

Objective-C Cocoa objects can be either mutable or immutable.  Immutable objects contain encapsulated objects that can not be changed after they are created.  The encapsulated objects inside immutable objects have values that will remain the same for the life of the object.  If an encapsulated object is inside a mutable object, the value can be changed at any time.

Cocoa objects are mutable by default and most will let us change their encapsulated data when we use setter and getter methods.  I setup my setters and getters by synthesizing my property declarations (model objects) from my .h file in my .m file.  Model objects require setter methods before we can change the instance data.

The Foundation framework introduces mutable and immutable classes.  The mutable subclasses are usually subclasses of their immutable superclass and they are easy to recognize because they use the word “Mutable” in their class name.  Examples:  NSMutableArray, NSMutableData.  The Foundation framework defines all mutable classes.  The AppKit framework includes NSMutableParagraphStyle and any Cocoa framework might have it’s own mutable and immutable classes.

Immutable objects can be ones that encapsulate collections of discrete values or contain values that will be stored in buffers. Immutable objects’ values are stable in theory but not guaranteed.  If serializing a property list with NSPropertyListSerialization, the mutability is not preserved because only the general object mutablity is preserved (dictionary, array..).  So when we deserialize the property list, the resulting objects may not be the same class as the original objects.  Maybe the NSMutableDictionary object is now a NSDictionary object.

NSNumber or NSDate can be mutable objects because they contain a single simple value.  Mutable objects might be less efficient than their immutable counterpart because they must dynamically manage a backing store that is able to change.

Using Mutable Objects

  • Use mutable variant of an object when we need to change its contents frequently and incrementally after it’s been created.
  • Look at return type for indications of mutability.
  • Go with immutable if you have any doubts about if an object is or should be mutable.
  • Most instance vars holding string values should be assigned immutable NSString objects that are replaced with setter methods.  Sometimes it’s preferable to replace one immutable object with another.

Create and Convert Mutable Objects

Use standard nested alloc-init.

NSMutableDictionary *mutDict = [[NSMutableDictionary alloc] init];

Use initializers and factory methods.

NSMutableArray *mutArray = [NSMutableArray arrayWithCapacity:[timeZones count]];

Make a mutable copy of an existing object by invoking mutableCopy method that each immutable super class of a Foundation mutable class uses.  Or you can send copy to a mutable object to make an immutable copy of the object.

NSMutableSet *mutSet = [aSet mutableCopy];

Storing & Returning Mutable Instance Vars

Use immutable when an object has contents that will change alot.  Strings and data objects are usually immutable.  Use mutable when an object changes incrementally.  Collections, arrays, and dictionaries are usually mutable.  Frequency of changes and size of collection should also be considered when deciding to make an object mutable or immutable.  A small array that rarely changes should be immutable.

Use immutable if we are at risk of mutating something the end user might have reference to, such as a collection that frequently changes and is returned to user via a getter accessor method.

If the value of the instance var changes frequently but we rarely return it to clients in getter methods; make the instance var mutable but return an immutable copy of it in the accessor method.

Maintain a flag that records if the object is currently mutable or immutable.  If there is a change, make the object mutable and apply the change.  When handing out the collection, make the object immutable before returning it, if needed.

Receiving Mutable Objects

The method invoker wants to know if the object’s value can be changed and if the value will change unexpectedly while it has a reference to it.  Don’t use introspection, use return type instead.  Do not assume an object is mutable based on its class membership.  Base my decision solely on what the signature of the method vending the object says about it’s mutability.  If I’m not sure, assume it’s immutable.

Make Snapshots of Received Objects

If I want to make sure an immutable object received from a method will not mutate without me knowing about it, make a snapshot of the object by copying it locally and occasionally comparing to the stored version of the object with the most recent version.  If you see the object mutated, adjust your code where it is dependent on the previous version of the object.  Making snapshots can be an expensive problem because we are making multiple copies of the same object.  Use key-value observing for an efficient alternative.

Mutable Objects in Collections

Problems can happen from storing mutable objects in collection objects.  Some collections turn invalid or corrupt if the objects they hold mutate because the objects affect the way they are placed in the collection.  The object properties that are keys in hashing collections (NSDictionary or NSSet) will corrupt the collection if they affect the object’s hash or isEqual methods when they change.  If an object in an ordered collection (sorted array) changes its properties, it will affect how the object compares to other objects in the array, rendering the ordering invalid.

References:

Object Mutability.  Concepts in Objective-C Programming.  Mac Developer Library.  Retrieved November 29th 2012 from http://developer.apple.com/library/mac/#documentation/General/Conceptual/CocoaEncyclopedia/ObjectMutability/ObjectMutability.html

Mobile App Developer. What to expect when hiring me.

Some of my past clients share what it’s like for them to hire me and you can see what they say at LinkedIn.  I’m flexible and can join projects in any phase with small, medium, or large teams.  I still attend University full time, so I am available for small part time projects to develop mobile apps (native iOS, Android, web, and hybrid).  I work with both pc and apple development and design environments.

WEEK ONE

HIRE ME & SCHEDULE MEETING.  I receive your retainer fee to hire me to develop your mobile app idea.  Your retainer fee covers up to 5 hours of my time.  After I receive payment, I will schedule an online meeting with you, to help me define what your mobile app requirements and goals are.  I send you a client questionnaire that you need to answer and send back to me before our first  meeting.  I setup a private online sign in where you will have access to everything that is relevant to your mobile app project.

FIRST MEETING.  You and I discuss your mobile app idea, goals, requirements, challenges, and targets with you for 1 hour online via Google+ Hangout, Skype, Instant Messaging, or similar online meeting technologies.  This meeting helps me to define your goals, requirements, and more so that I can start preparing documentation for the next project phase.  Your retainer fee covers the costs and time for this first meeting.  You and I will discuss a payment schedule and terms to cover my time and expenses for developing your mobile app.

ONE TO TWO WEEKS

MOBILE APP UX DOCUMENTATION.  I start with a clear definition of your mobile app idea, goals and targets. Next I develop a target audience screening survey, a prototype of the mobile app idea, and a usability survey.  I analyze and provide the results in your documentation.  3 to 6 Goals, 2 User Personas, and 3 to 6 Main Features suggested for your mobile app idea.  I also include short screencast video reviews (5 minutes or less) of the mobile app idea, prototype, mobile app testing results.  Examples of my video reviews:  http://www.YouTube.com/monigarr  You will review this documentation within 48 hours that I submit it to you and you will let me know if anything needs to be changed or added within 48 hours after I submit the completed documentation to you.

ONE TO FOUR WEEKS

MOBILE APP PROJECT PLAN.  I define the project requirements for each team member, skills, equipment, specialists, labor, licensing, content providers, and technologies that will be used.  I also define the project milestones, work schedules and financial budget.  Mobile apps can be web based or native.  Hybrid mobile apps are web based that have been converted to Native.  Each choice has it’s pros and cons that will be described in the project plan.  I  will contact you via email with questions and you will need to respond via email asap.  Within 48 hours after I submit this to you, you will need to let me know if anything needs to be changed or added.

ONE TO FOUR WEEKS

MOBILE APP DEV & DESIGN TEAM.  I setup a private online collaborative environment for everyone on the team to have easy & fast access to communicate with each other as needed and verify that everyone has access to everything they need to get their work done. I start recruiting team members to join us if needed (graphic designers, content providers, third party resources…)

ONE TO FOUR WEEKS

MOBILE APP DEV & DESIGN.  I receive and setup content from providers.  I receive and setup licenses for sdks, app stores, and content. I receive content from you regarding business contacts, descriptions for the mobile app marketing & development.  I develop the mobile app’s features, graphics, animations, video, and audio.  I integrate third party resources as needed for social networking, ecommerce, maps, and other relevant content.  I consistently refer to the Mobile App UX Documentation and Project Plans to ensure that all features and visuals are aligned with all of the business logic and requirements.  Each week I will create a 5 minute video screencast to provide an overview of the work I did that week.  You must contact me within 24 hours after receiving the video screencast to let me know if you want anything changed or added.  If changes or additions are requested at this phase of the project, we may need to stop development work and start over with the UX Documentation phase to ensure that all the foundation and ground work is clear & concise – especially for projects that involve investors.

ONE TO FOUR WEEKS

MOBILE APP BETA TESTING.  I create public online sign up for the Mobile App Beta Test.  Participants sign themselves up and send invitation for others to sign up online.  EULA agreement must be agreed to by the participants.  I create an online beta test and ask the participants to complete up to five tasks while they test the Mobile App.  When the participant completes the five tasks they are asked to answer five questions with an online survey.  The online survey can be anonymous or the participants can enter their contact info for a chance to win a prize that is relevant to the goal of the Mobile App.  I collect, analyze, and report the beta testing results with documentation and video reviews for the client.  You will need to contact me within 48 hours to discuss project changes and additions (this might require us to go back to the UX Documentation phase).

ONE TO EIGHT WEEKS

Mobile App Submitted to App Stores.  I prepare your mobile app to be submitted to the relevant app stores with descriptions, textual content, and visuals that follow the standards defined by each app store.  Mobile App Stores might take up to 8 weeks before they will approve a mobile app to be allowed in their store.  Sometimes they ask that the mobile app be changed before they will allow it to be sold from their app store.  I work with the app store to complete any requested changes and resubmit.  I will send you a message every few days to let you know the status while we wait for app store approval.

Mobile App Webpage.  I create a webpage to help you promote your mobile app and provide users with a Share button to send a link to social networks and email contacts.  Standard SEO and SMO features will be included.  The webpage directs targets to the mobile app stores where they can purchase and download your mobile app and rate your mobile app.

The whole process of making your Mobile App Idea a reality and seeing it sold in App Stores can take anywhere from 2 Months to 1 Year depending on how the whole team works together.

Mozilla Developer Network Dev Derby October 2012 Challenge; CSS Media Queries

This is my entry into the monthly challenge for Mozilla Developer Network’s Dev Derby. I used various pictures of Mother Monster to show how CSS3 Media Queries can be used to develop and design Responsive websites for screens of any size. One webpage will responsively change it’s content, format, and sizing based on each individual’s different screen size.

Native mobile apps I developed in November 2012 for iOS6, iPhone, and iPad.

I create weekly videos to show the mobile app I developed and designed that week. These videos show my progress and increased skills as a mobile developer in the Full Sail University Mobile Development Course. I also learn from Team Treehouse, Lynda.com, OReilly.com, and SitePoint. Each video is 5 minutes or less.

Fitness Mobile App

Mapkit Mobile App

Raw Vegan Mobile App 2

Raw Vegan Mobile App 1

Responsive WordPress Themes for All Devices

I finally found time to edit my own website and wordpress theme to make it more responsive for all screen sizes. I’m using the Portfolio Press wordpress theme from Devin Price because it is awesome for a self-hosted wordpress blog for busy web developers and designers to showcase
their most recent projects. It’s already responsive for the most part, so I only had to do very minor edits to the stylesheet and change the px sizes to em sizes for my header, fonts, margins, and other similar html elements.

I used PXtoEM.com to convert the px sizes to em sizes. The one element that should be left as it’s original px size is the #logo #site-title in the css file. If you change it to the em size, it will look ridiculously huge on big screens and ridiculously small on small screens. It’s the logo and site title so it works better with this particular web design when it’s left as a static px size.

Another example where I show the possibilities of Responsive Web Design using CSS3 Media Queries can be seen on the Mozilla Developer Network’s Dev Derby Challenge for October 2012. I used images of a popular modern entertainer to show how the images will be changed according to the screen size of each viewer looking at the webpage.

We can use Javascript and CSS to create awesome Responsive Web Designs, but it’s possible to accomplish this by using only CSS3 Media Queries too and that can help us in regards to ensuring a webpage loads faster while maintaining a human friendly User Interface and User Experience.

Resources & Inspiration:

Responsive Design: Fluid Grids & Sub-Pixel CSS Problems

You want your web design to be fluid and resize when the web browser window is re sized?  This article will walk you through the process of making that happen.  Please note that I learn from websites that I highly suggest you visit daily like I do.  The most awesome original article that I learned about fluid grids is online at Continue reading

Testing Responsive Design

Here is a list of various online tools for anyone that is planning to create a new mobile Internet business model, web app or native mobile app.  The links in this article test responsive design elements and provide mobile emulators. Good responsive design is when a website responds to each unique visitor’s screen resolution, language, input, and other interactivity with a relevant response.  One of the best websites to learn all about Responsive design is Continue reading

Posted in Mobile | Comments Off

Website Pitfalls & Solutions

I’m going to highlight some of the most important features that your website, mobile web apps, and native apps absolutely must provide, if you are truly serious about providing your end users with the best User Experiences possible.  Please note that these necessary features are no more or less important than the next one.  If just one of these features is failing the whole project can amount to Continue reading

Posted in Mobile | Comments Off

Ansca Corona SDK for mobile development.

I will start by saying that I’ve decided to focus mainly on iOS development for my career as a freelance mobile developer.  Of course I still keep my eyes and ears open to everything else too.  I like developing android apps too, but I don’t plan to focus my efforts and investment in that direction. Continue reading

Posted in Mobile | Comments Off

How to Setup Modernizr JavaScript Library

I use Modernizr JS library to add HTML5 features to websites.  HTML5 is a mix of HTML, CSS3, and JavaScript.  Web browsers do not always support HTML5 markup and the ones that do support it, provide support in different ways.  Modernizr provides a consistent user experience to all the different web browsers that view my websites.  Modernizr detects what HTML5 features each browser supports by creating an element, setting a style to the element, and then retrieving the element.  If a browser can’t handle Continue reading

Posted in Mobile | Comments Off