What’s in store for holiday decorating this year? A survey of U.S. Houzzers found that one in six holiday decorators plan to go “over the top” (16%). Another 60% describe their décor style as “festive” and 22% take a “minimalist” approach. Making things merry and bright doesn’t mean breaking the bank, however. The majority of holiday decorators plan to spend less than $50 on new items this year.
Holiday décor isn’t just about seasonal sprucing. Sixty percent of survey respondents expect to host overnight guests this holiday season. Of those, one-quarter plan to redecorate a guest bedroom and/or bathroom (25%), and one in ten plan to renovate (10%). Making sure the fridge/pantry is stocked and deep cleaning the house top hosts’ to do lists (87% and 78%, respectively).
While the jury’s still out on whether or not Santa is real, the survey revealed that the majority of Christmas trees are not. In fact, artificial trees are twice as popular as real ones (72% vs. 35%, respectively). Candles top the list of must have holiday decor and will make appearances in four in five homes (83%).
Nearly half of respondents reported that pulling their decor out of storage is the most stressful part of the holiday decorating process (44%). Perhaps in an attempt to curb this stress the following year, nearly one in five report that donating/throwing away decor they no longer want is their favorite part of the holiday decorating process (18%).
New data released from the 2016 U.S. Houzz & Home survey found that over one-third of homeowners on Houzz (68 percent) plan to include a recreational area in their newly-built custom home. The most popular rooms for fun? Gaming and entertainment rooms top the list with appearances in over one-quarter of custom built homes (29 percent), followed by home gyms (22 percent), libraries (18 percent), home theaters and kids’ playrooms (both 17 percent). Kids playrooms are especially popular among Millennials (38 percent) and Gen Xers (24 percent).
This customization is just what people crave with nearly half of homeowners opting to build versus buy because they have a specific vision for what a home should be (48 percent). While the majority of those building a custom home use custom drawn plans (62 percent), a significant number also use ready-made plans that they modify (32 percent). For most homeowners, building a dream home means staying put for the long-term, and this increases with age. Forty-six percent Millennials, 51 percent of Gen Xers, and 59 percent of Baby Boomers say they have no plans to ever move from their custom home.
While achieving a specific vision for a home is a key motivation to build, over a quarter of Millennials opt to build because of greater affordability (26 percent) versus just 11 percent of Gen Xers and seven percent of Baby Boomers. In keeping with this, Millennial homeowners spend significantly less on custom home building than their older counterparts. While the average spend on custom home construction for those who completed projects in 2015 on Houzz was $942,000, Millennials spent an average of $423,100, followed by Gen Xers at $714,300, and Baby Boomers at $1,168,600.
More than half of those who finished a custom home build in 2015 went over budget (53 percent). Choosing more expensive products or materials is the leading budget buster (63 percent), followed by products or services being more costly than expected (44 percent), and changing the product scope or design (30 percent). When it comes to financing, more than half of new custom home builds are funded by savings/personal finances (56 percent), followed by construction loans secured by the home’s value (44 percent).
Between customization and the large investment for a forever home, it’s no wonder that the vast majority of homeowners hire professionals to help with their project (95 percent). Builders top the list (63 percent), followed by architects and general contractors (both 38 percent). Many homeowners hire specialists for their projects as well, including electricians (55 percent), cabinetry specialists and plumbers (both 49 percent).
The average custom built home features three bedrooms and three bathrooms. Baby Boomers are most likely to build a single-story home (39 percent versus 28 percent for Millennials and 25 percent for Gen Xers). Meanwhile, more than one-quarter of Gen Xers (27 percent) and nearly the same number of Millennials (25 percent) are building homes with three or more stories.
The Houzz & Home Survey was sent to registered users of Houzz and fielded in March-June 2016. The Farnsworth Group, an independent market research firm, conducted the survey. Among the more than 120,000 survey respondents in the U.S., more than 6,500 are in the midst of, are planning, or have recently completed a new home build. Check out the full report at http://info.houzz.com/HH2016.html.
Mindy focuses on building the user interface for Houzzers as a front-end engineer, from enhancing the photo browsing experience, to redesigning user profiles, to creating a home for Houzz TV. When she’s not at work, she can often be found hiking with her husband and her Shiba Inu, Maui, or tackling a remodeling project at home.
What sparked your interest in computer science? I was really into art when I was growing up in Taiwan – I’ve always enjoyed making things, from sewing to craft projects. When I was in a high school computer class, I learned Flash to make simple animated games. That’s when I discovered how fun it is to create something using a computer. I enjoyed it so much that I decided to study computer science in college, and then grad school. This is also why I wanted to become a front-end engineer, specifically – I enjoy building things that people can see and interact with.
Why did you decide to join Houzz? In addition to computer science, I also love interior design. My husband and I were actually in the process of purchasing our home at the time – an Eichler – and thinking about how we would make it our own. Working at Houzz has given me a great opportunity to put both of these interests to use.
What’s your favorite part of working at Houzz? The people and the culture. For the first time in my career I feel like I work with friends, with family. People like to help and influence each other here, like a friend or a family member would. We support each other, and we learn a lot from each other every day.
We also have a lot of fun together. For instance, decorating our desks with rubber duckies is a Houzz tradition we all love.
What’s something that has surprised you about working at Houzz? We have a lot of freedom to drive our own projects at Houzz. This hasn’t changed in the four years that I’ve been a part of the team here. We’ve grown a lot as a company in that time, and it’s amazing that we’re able to maintain the same atmosphere in the office now as when there were only 30 of us. Being a flat organization, we still have the ability to work without a lot of unnecessary processes, and have the opportunity to work with a wide range of people – not just other engineers. Our day-to-day life hasn’t changed…we’re just a much bigger family now.
What’s your favorite thing you’ve worked on at Houzz? I really enjoy working on new designs that continuously evolve our website. It feels like Houzz is our home, and we’re redecorating it! One of my recent favorite projects was creating a home for Houzz TV. It’s exciting that we’re providing Houzzers with an opportunity to experience Houzz in a new way, through video.
What’s the development process like at Houzz? It’s very collaborative. Our team involves everyone from the very beginning of a project, and we’re all able to offer our ideas right from the initial iteration phase. Once we’re all happy with a solution we continue to A/B test it to make sure our community is just as pleased as we are.
When do you write your best code? In the afternoon. I like to triage any necessary fixes that come through over email first thing in the morning, so I can focus on coding in the afternoon. Our team doesn’t hold a lot of meetings, so we’re able to concentrate on getting our work done.
How have you used Houzz at home? My husband and I have taken on several renovation projects to make our home our own since we bought it four years ago. So far we’ve updated our living room, two bathrooms, and the backyard. We used Houzz to create ideabooks to gather ideas for all of these spaces, buy materials and collaborate with each other and the pros working on the projects. We’ve done this all slowly over the years. Rather than completely updating a home as soon as I move in, I prefer to live in the house for a while and see what it needs over time.
What’s the style of your home? Since it’s an Eichler, the overall design of the home is mid-century modern, though I gravitate toward a modern minimalist style. I like things with clean lines, but not too much black and white – I like a splash of color. I think I’ve seen this style described as “happy modern.”
What do you like to do when you’re not working? My hobbies keep changing! My husband and I spend a lot of time traveling and hiking with our Shibu Inu, Maui. We are also almost always in the middle of a renovation or decorating project. I also spend a lot of time on Houzz, of course, testing the products I’m working on, but also enjoying the site. This definitely inspires more projects!
As homeowners renovate their homes, nearly half are using the project as an opportunity to integrate “smart” technology, as revealed in our recent 2016 Houzz Smart Home Trends Survey. The driving factors behind the installation of smart tech – systems or devices that can be monitored or controlled via smartphone, tablet or computer – vary depending on the type of technology. Let’s take a closer look at the primary motivations behind smart security/safety, climate control, lighting and entertainment upgrades.
Homeowners are particularly keen on adding smart security and safety features to their renovated homes (25 percent). Interestingly, protection against intruders – the top motivation for security upgrades across the board – is a stronger motivation for those installing smart security/safety features than those installing non-smart options (67% vs. 51%, respectively).
Given that smart security/safety features provide homeowners with the unique ability to monitor or control the protection of their home remotely, it makes sense that these factors are also major motivators behind smart home product integration. This includes having the ability to monitor or control the security/safety of the home from outside of the home (52%) and from anywhere within the home (30%).
When it comes to entertainment upgrades, homeowners are largely drawn to smart technology options to create the best, most comfortable, and most technologically advanced experience possible. Improving the entertainment experience is the top motivator (80%, ahead of non-smart upgrades at 75%), followed by improving the comfort (55%, ahead of non-smart upgrades at 47%). The desire to have the latest technology or the ability to easily change the mood or vibe of the home come next (27% each).
Reducing energy consumption and improving the comfort are the top motivations behind both smart climate control and smart lighting upgrades. Comfort is king when it comes to installing smart climate control devices (71%), followed closely by reducing energy consumption (68%). Optimizing energy consumption is a slightly higher motivator among smart device installers than non-smart device upgraders (68% vs. 62%, respectively). The ability to monitor or control the climate of the home from outside the home comes third (41%).
Reducing energy consumption is an even stronger motivator for smart lighting installers than non-smart lighting upgraders (59% vs. 47%). Improving the comfort of the homeowner/homeowner’s family is the next highest motivator for smart lighting upgraders (54%), followed by the ability to easily change the mood or vibe of the home (34%).
A common thread between all four of the smart home categories covered in this survey – security/safety, climate control, lighting and entertainment – is that improving resale value through the installation of smart technology is a low priority. This was a motivating factor for only 16% of lighting, 14% of climate control, 11% of security/safety and 8% of entertainment upgraders installing smart products. Instead, homeowners report being more interested in improving the overall comfort, enjoyment, and efficiency of their homes, for themselves and their families.
Today we’re excited to introduce Visual Match. Our new visual recognition feature helps people close the gap between getting inspired from what they see in the photos on Houzz, and actually finding and purchasing products suited for their own spaces and budgets.
Powered by deep learning technology, Visual Match scans the more than 11 million photos on Houzz to identify similar products, from tables and sofas to mirrors and plumbing fixtures, and more, and serves up examples of those products that are available for purchase on Houzz.
To use Visual Match, simply hover over a product in a photo on Houzz, click the magnifying glass, and we’ll surface visually similar products from the Houzz Marketplace. There are now more than 6 million products available for purchase from over 15,000 merchants on Houzz today.
Visual Match is the latest example of how we are reimagining the shopping experience through new technology. Now, people can view a photo in the Houzz app, tap a product in the photo that they love, find similar products available for purchase on Houzz through Visual Match, and use View in My Room to see the product in their own space.
Visual Match is available for desktop and in the free Houzz app for iPhone®, iPad® and Android™.
As a product designer at Houzz, Andrew’s responsibilities span everything from creating custom illustrations to designing the user experience for new features. Outside of work, you can likely find Andrew on the basketball court.
How did you get into design? I’ve been interested in art and design for as long as I can remember, but I didn’t think about it seriously as a career path until high school. I originally thought about going into architecture – when you have strict parents, and you’re interested in design, architecture is often an acceptable middle ground. But when I got to college and began to learn more about the field, the quick turnaround in graphic design projects seemed like a better fit for me than the often longer term projects in architecture. So I decided to pursue graphic design instead.
While I was at school I had an internship that gave me the opportunity to work on a couple of mobile apps. I realized that there’s much more to mobile design than how things look – it’s also about how people use the app. That’s what inspired me to get into this field.
Where do you get your inspiration? I find inspiration by observing people, and how different people use things differently. I like to visit sites like Designer News, where a lot of designers in the tech industry share articles and other resources. It’s a great way to learn about the “latest and greatest” news and tips for working more efficiently. My girlfriend is also a designer, and we chat about design quite often. We critique each other’s work sometimes, and we’re pretty ruthless about it. We really appreciate each other’s honesty – we know it’s not personal. If something’s terrible, we’ll tell each other!
What’s something that has surprised you about working at Houzz? Everyone has a voice here. If you make a compelling case, you can make a difference. We’re also allowed to be creative in a way that you’re not often able to be at other companies. When I’m given a project, I’m not always given all of the specific requirements – it’s often up to me to explore different ways to achieve our goals. This really facilitates innovation.
What’s your favorite thing you’ve worked on at Houzz? I’m currently in the process of working on redesigning a section of the site that I think will make a lot of people happy. It’s a project that involves a lot of complex problem solving, and gives me the opportunity to experience working on aspects of design that I’ve been interested in since I got into this field.
How do you use Houzz? Houzz was my go-to resource for inspiration and advice during my recent kitchen and bathroom renovation. I have a tiny kitchen, which takes careful planning to make use of the little space there is. The wealth of knowledge from the Stories and Advice sections on Houzz really helped me achieve that – my cabinet vendor was surprised when I requested pull-out pantries and trash cans!
What’s the style of your home? It’s a mix between eclectic and midcentury. I like my home to feel warm and homey. My walls are all white but with a tint of yellow, for example. I just searched for photos of “warm white” spaces on Houzz and drew inspiration from there.
What should a design candidate know about working at Houzz? At Houzz, you’re not restricted to being just a designer. You often get to wear different hats, and don’t work in silos – it’s good to have relationships with people from various teams throughout Houzz who can help you achieve those different tasks. Everyone at Houzz is awesome about helping each other.
What do you like to do when you’re not working? Basketball – I play with other Houzzers, and also on a recreational league. I think it helps with work, too – it’s a good reminder to stay competitive, not with my colleagues, but within the industry. Basketball reminds me not to be complacent – it gets me fired up.
Houzz Spain had a unique opportunity at this year’s Casa Decor event in Madrid, the largest annual interior design and architecture showcase in Europe. The team worked with Houzz professionals to design and build a physical space at the show, bringing the latest trends in kitchen design to life. The space also served as a physical example of how homeowners and professionals leverage Houzz to take their design ideas from dreams to reality.
Over the course of two months, the team worked with architecture firm Infiniski, found on Houzz, to create a modular open kitchen and living area. The design was inspired by the results of the Houzz Spain Kitchen Trends Study, which found that homeowners gravitate toward open spaces that blur the lines between the kitchen and other living areas. The survey also revealed that homeowners favor kitchens that open into the outdoors, which led the team to design a space that flows easily into a serene patio and garden.
Nimú, a design firm based in Madrid, filled the kitchen with rich wood, brass, and marble accents, as well as a vibrant mosaic floor. Many of the furnishings, lighting and materials throughout the space featured signature Houzz green tags, reflecting the experience on Houzz.
Thanks to its sustainable design, the structure was broken down and easily recycled following the event – though not before Houzz Spain leveraged the stunning space to celebrate their one year anniversary alongside over 70 guests.
Check out the ideabook here and video below documenting the space’s creation start to finish – en Español, of course!
Do you and your partner compete for counter space in your master bathroom each morning? You’re not alone. The 2016 Houzz Bathroom Trends Survey found that most homeowners renovating their master bathrooms share that room with a partner (75%). And nearly 40% of master bathroom renovators cite a space that is “easy for more than one person to be in” as the top functional aspect of their upgraded rooms. Given this, many master bathroom renovators are investing to create luxurious spaces that are ideal for sharing.
Nearly three-quarters of renovated master bathrooms include distinct, private areas, making it easier for two people to share the room at the same time. Fully or partially walled-off spaces for showers, toilets and vanities are especially common (47%, 46% and 27%, respectively). Master bathroom renovators also gravitate toward double sinks in their updated rooms (66%), easily accommodating two people at once.
Renovating homeowners are also installing luxury features for two in their updated master bathrooms. One in five master bathroom renovators updating their shower select a dual shower design (21%), and a similar proportion of bathtub upgraders choose a tub with space for two (20%). Additionally, the majority of shower upgraders are supersizing the footprint of their showers (69%) – a third are expanding their shower by half or more (30%).
Beyond establishing spaces easily occupied by two, master bathroom renovators are also creating stylish, beautiful rooms worth lingering in. Four in five homeowners renovating master bathrooms prioritize style and beauty far above all other design aspects, including resale value (81% vs. 48%). To do so, homeowners are investing in upgrades of major features, including faucets/plumbing fixtures (94%), wall finishes (92%), flooring (91%) and countertops (89%).
Nine in ten homeowners change the style of their master bathroom during their project (90%), gravitating toward contemporary, modern or transitional styles in their upgraded rooms (27%, 17% and 16%, respectively). Given how infrequently these rooms are renovated, homeowners tend to choose neutral palettes that stand the test of time, such as gray walls and floors (29% and 26%, respectively), and white countertops and cabinets (36% and 34%, respectively).
For more insights from the 2016 U.S. Houzz Bathroom Trends Study, check out the full report here.
As a designer at Houzz, Dave’s work ranges from crafting the user experience to designing pixel-perfect screens and icons for Houzz’s iOS and Android apps. Outside of the office, you can find him watching the Giants or A’s game (he’s a fan of both, having lived for years in both SF and the East Bay), or checking out the latest restaurant to open in his San Francisco neighborhood.
How did you get into design? My interest in photography and video editing eventually led me to the design field. When I went to grad school I discovered my niche in user experience design and just went with it.
Where you do get your inspiration? I listen to a lot of podcasts, read a lot, and download a lot of apps. I also like to get inspiration through research – it’s an important part of my job, and it’s something that I really enjoy, looking around for new and interesting things. A lot of my inspiration comes just from browsing the App Store or Google Play for apps that interest me. Sometimes I’ll ask others for recommendations for apps they’ve used that they really like or have solved a problem of theirs. What inspires me most is seeing someone’s reaction to experiencing an app (or anything) that they really love.
What’s your favorite design resource and why? I look at a lot of different sources…Designer News, Twitter, Invision Blog, Instagram, etc. I like checking Twitter and Instagram because they offer such a big mashup of raw inspiration. The Invision blog is more curated and focused on distinct ideas.
What’s your biggest design pet peeve? Oversimplified design.
What’s your favorite part of working at Houzz? Our amazing team, and the freedom we have to be creative. The strength of our team has been a constant since the day I joined Houzz – initially I was surprised by how great and smart everyone was, and I’m really happy that I feel even more confident about our team today.
What’s your favorite thing you’ve worked on at Houzz? Every project is a new experience and a new opportunity to grow as a designer. My favorite project I’ve worked on so far is the navigational redesign we did about a year ago. It was an opportunity to really improve a lot of areas in our app, and was something that I’d wanted to accomplish for awhile.
What’s the style of your home? I’m currently renting my apartment in San Francisco. My style is an odd blend of modern/eclectic/design elements with a bit of “old rickety San Francisco apartment” thrown in. I try not to stick to one strict style, while avoiding mixing too many things together.
How do you use Houzz? I use Houzz mostly to furnish and decorate my home. Space can be tight in San Francisco, so I really like looking for ways to maximize the space I have. I’m looking forward to the day when I can hire a pro and remodel a home – I already have a lot of ideas.
What do you like to do when you’re not working? I like to watch and play basketball and baseball, read, drink coffee, and try new restaurants in San Francisco – it seems like there’s a new one opening every day!
At Houzz, we’ve developed a solution for JSON parsing in Swift that can save developers a lot of time while supporting all the great characteristics of Swift – namely, type safety, marking model properties as read only, and supporting pure Swift classes (not derived from Objective C) and Swift structs.
The difficulty with parsing JSON in Swift is that it is a strongly typed language, while JSON is loosely typed and JSON tags don’t carry type information and can carry a payload of any type. This requires quite cumbersome code to perform all the needed type checks and to handle all the fallbacks. An added difficulty comes from Swift’s strict adherence to its two-phase initialization, requiring you to initialize all class properties before calling methods on it.
There are several open source libraries already available for parsing JSON in Swift. The first type of libraries simply manage a lot of the complexity in type checking the JSON. These include libraries like Unbox, SwiftyJSON or JSONCodable. While they do reduce the complexity in parsing, they also involve writing a lot of boilerplate code, which we wanted to avoid. In addition, we wanted the solution to also support NSCoding and NSCopying out of the box, as our objective C-based solution does.
In objective C we used a runtime introspection-based solution, similar to JSONModel, except it is a homegrown solution tailored to our needs. The advantage of such a solution is that there is no boilerplate code needed. Just declare the properties you expect to get from the JSON and the runtime introspection will populate the properties based on the data read from JSON. Similar solutions exist in Swift, such as EVReflection. All you need to do is inherit from the EVReflection base object (which was another downside for us, as we wanted to control the class hierarchy) and define the properties you want to extract from the JSON. The downside is that in order for this to work, all the properties need to be defined as read/write, that is as var properties. We wanted to clearly mark in the code which properties came from our server and are part of our data model, and therefore shouldn’t be written to locally. Swift requires these to be var properties due to the init phases in Swift, and the compiler verifying all properties were initialized in the class init. This limitation eliminated any dynamic runtime solution for us.
A third type of solution is graphical tools that can parse the JSON and code generate Swift classes from the JSON. SwiftyJSONAccelerator and JSONExport are examples of such tools. The problem with these solutions is that our JSON API evolves over time, so our objects add properties as the API and data model evolves. We wanted a quick and easy way to update our existing models. Also, being developers, using a text-based solution, preferably similar to source code we know, that is easily source-controlled, is more in our nature.
These led us to the solution we finally chose. We used a code generator to create all the boilerplate code for us, based on a Swift-like class definition, and used Xcode’s built-in ability to define build steps to automatically add the code generation into our build flow. Using this solution, we don’t spend time writing parsers, we just declare our model properties in the most natural syntax for developers, a Swift-like file.
The Cast File We define our classes in a .cast file which has a Swift-like syntax. It will also use the Xcode syntax highlighting, and as we’ve pointed out, properties can be either defined as let or var. So let’s jump into the first, simplest class example:
class Person: NSObject, DictionaryConvertible {
let firstName: String
let lastName: String = "x"
let middleName: String?
let yearsOld: Int //! "age"
}
This defines a Person class. It derives from NSObject, and by indicating that it conforms to the DictionaryConvertible protocol, the code generator knows this is a class for which an init(dictionary:)? needs to be generated. The DictionaryConvertible protocol defines two methods, the init which gets a dictionary parameter (a dictionary that is the result of NSJSONSerialization), and a DictionaryRepresentation method which does the opposite – given an object, it returns its dictionary representation. It also defines an overloaded init(json:)? Initializer that can get a JSON parameter either as a Data or as a String object.
The Person class defines a required property, firstName. This is non-optional – if the dictionary doesn’t have a “firstName” key, the init will fail and return nil. The Person class also contains a lastName optional property. If the dictionary doesn’t have a “lastName” key, the lastName will get a default value of “x”. The last property, “middleName,” is also optional. If the dictionary is missing this key, middleName will be nil. The last property, “yearsOld,” is an Int but is read from the dictionary key “age”. The //! is the form to add special directives to the code generator. So //! “Key” is how you override the default property name to key name mapping. You can also use this to pick up nested keys. //! “Outer/inner” will look in the dictionary for the key “Outer” which should have a dictionary value, this dictionary should have the key, “inner.” The reason we chose a failable initializer rather than a throwing one is since we do still have objective C in our code, and our models sometimes need to be called from objective C as well, a fail-able initializer is compatible while a throwing one isn’t.
We also wanted our model classes to automatically support NSCoding and NSCopying. Our objective C JSON serialization solution did that, and we find this useful, particularly in save state when you have to serialize the app’s data. To support NSCoding and NSCopying, simply declare your class as conforming to these protocols. The code generator will detect this and generate the required methods to conform to these protocols. In order to do this, your class must derive from NSObject, which raises another feature of the code generator – there is no need to derive from NSObject just for conformance to the DictionaryConvertible protocol. A pure Swift class will work as well. In fact, you can also declare your object as a struct.
Integrating into Xcode To build the cast file, one needs to add a build rule to Xcode. This is done from the build rules tab in the project settings as follows:
Now tapping build will create a .Swift file from the .cast file and compile it into the project.
The simplest way to add a cast file to your project is to add a Swift file using Xcode’s file template and rename it to .cast. Alternatively, if you add a cast file directly, remember to add it to the source files list in the project settings. To enable syntax highlighting in the file inspector, change the cast file type to Swift source code as shown.
To complete the integration, add the cast framework to your project.
The Cast Framework and Mapper Class The generated file will import the Cast framework. This framework defines a single class, Mapper, that has two class functions, map and unmap. The code generator is using the map function when converting values from the dictionary and assigning them to the property values. The map function is an overloaded function that get an AnyObject parameter and returns the requested type. The implementation of the Mapper class in the Cast framework supports the following types: String, Int, UInt, Float, Double, CGFloat, NSURL, and arrays of these types. It also supports any type that conforms to DictionaryConvertible, so you can easily create properties that are of other DictionaryConvertible types. If you want to add support for a new variable type, such as NSDate, extend the Mapper class and add a map(_:) implementation that returns the type you want. To continue the NSDate support example, if our JSON contains dates as number of seconds from 1970, our Mapper extension would be:
extension Mapper {
func map(object: AnyObject) -> NSDate? {
switch object {
case n as Double:
return NSDate(timeIntervalSince1970: n)
default:
return nil
}
}
}
Note that we opted not to support dates by default, as dates can be sent in various formats. We opted to let developers add support for the date format they are expecting.
Other Factors Enum Support When using properties of type enum, if the enum is backed by a basic type, say a string or an Int, and the enum is defined in the .cast file, support is automatic. The code generator will pick up the enum definition and generate the correct code to parse the underlying basic type, and initiate an enum with a raw value. For any other enum type, the Mapper class needs to be extended to add support for this type. See previous section on how to extend the Mapper class.
AwakeWithDictionary If in the class definition in the .cast file you add an
//! awake
comment, the code generator will add a call to an awakeWithDictionary(dictionary: [String: AnyObject]) -> Bool function, passing it the dictionary used to initialize the object. If this function returns false, the init call will fail. This is your last chance to perform any special data verification on the object received from the JSON.
Extending the model If you need to add functionality to your model, that is add methods, the easy way to do this is by adding a separate extension Swift file, and adding your func code there. While it is possible to place everything in the cast file, we find it inconvenient as Xcode doesn’t have its full code completion functionality when editing a .cast file.
You can add in class extensions functions or computed properties, but not stored properties. If you need a stored property that should be ignored by the code generator and will not generate code to try, parse it from the JSON dictionary, add an ignore comment to the property definition:
var myProp: Int! //! ignore
Such properties have to be var properties. They need to be either optional, implicitly unwrapped optional or non-optional with an initialized value, I.e.
var myProp: Int = 0
Otherwise the Swift compiler will complain that the generated init method is not initializing all properties.
Inheritance If defining a class that inherits from a DictionaryConvertible class, the DictionaryConvertible deceleration can’t be added to the class or struct declaration. Any class in a .cast file that doesn’t contain the DictionaryConvertible protocol conformance deceleration is assumed to be inheriting from one that does, so the init method generated will call super to initialize the super class.
Since NSCoding conformance is optional, the code generator is not clever enough to figure out if the super class is conforming to it, nor does it have visibility into other .cast files. To tell the code generator the class needs to add NSCoding conformance, add a special comment to the class declaration:
//! NSCoding
The code generator will then generate the needed methods to add NSCoding conformance and call super.
Nothing needs to be done to add conformance to NSCopying since NSCopying is realized using the NSCoding methods.
Command Line Options The following command line options may be specified in the Xcode build rule when invoking the script to further control its behavior:
-c By default the key names that are searched in the dictionary are identical to the property names, so a property named firstName will be instantiated from the dictionary using the key “firstName.” If the -c option is provided, the key names will use an uppercase first letter by default, so “FirstName."
-i Will make the key lookup in the dictionary case insensitive.
-n Will make empty strings in the JSON (i.e. ”“) treated like nil values.
About the Script The script is written in Swift. Being Swift developers, this was the most natural choice and the one we felt will best leverage our skills. Written in Swift, it could easily be compiled into a binary command line tool (in fact, this is what the unit tests are doing), but the advantage of a script is that zero setup needed before building your project, and there’s no need to compile a command line tool first.
Swift 3 Ready The script is Swift 3 ready if you have already moved over to Swift 3. There is a Swift 3 branch in the code that you can use if you want the code generator output to be Swift 3. Remember to switch your Xcode command line tools environment to Xcode 8 beta if you are trying the script on Xcode 8 using the xcode-select command.
Code The code for JSON cast is available on github here.