Learn the Four Swift Patterns I Swear By
Free!
With Membership
$7.99
Suggested price

Learn the Four Swift Patterns I Swear By

About the Book

Swift is still very, very young and many developers are still figuring out how to best use the language. There are countless tutorials about patterns and best practices, which makes it hard to see the forest for the trees.

In this book, you learn the four patterns I use in every Swift project I work on. You learn how easy it is to integrate these patterns in any Swift project. I promise that they are easy to understand and implement.

#1 Namespaces in Swift

The first Swift pattern I use in every project that has any complexity to it is namespacing with enums and structs. Swift modules make the need for type prefixes obsolete. In Objective-C, it's a best practice to use a type prefix to avoid naming collisions with other libraries and frameworks, including Apple's.

Even though modules are an important step forward, they're not as flexible as many of us would want them to be. Swift currently doesn't offer a solution to namespace types and constants within modules.

#2 Dependency Injection in Swift

Dependency injection is a bit more daunting. Or that's what you're made to believe. Does dependency injection sound too complex or too fancy for your needs. The truth is that dependency injection is a fundamental pattern that's very easy to adopt.

My favorite quote about dependency injection is a quote by James Shore. It summarizes much of the confusion that surrounds dependency injection.

Dependency Injection is a 25-dollar term for a 5-cent concept. — James Shore

When I first heard about dependency injection, I also figured it was a technique too advanced for my needs at that time. I could do without dependency injection, whatever it was.

#3 Value Types and Reference Types

When talking about object-oriented programming, most of us intuitively think about classes. In Swift, however, things are a bit different. While you can continue to use classes, Swift has a few other tricks up its sleeve that can change the way you think about software development.

 

This is probably the most important mindset shift when working with Swift, especially if you're coming from a more traditional object-oriented programming language such as Ruby, Java, or Objective-C.

#4 Model-View-ViewModel in Swift

Model-View-Controller, or MVC for short, is a widely used design pattern for architecting software applications. Cocoa applications are centered around MVC and many of Apple's frameworks are impregnated by the pattern.

But there's an alternative that resolves many of the issues MVC suffers from, **Model-View-ViewModel**. You've probably heard of MVVM. But why is it becoming increasingly popular in the Swift community? And why have other languages and frameworks embraced Model-View-ViewModel for years?

I hope that my book helps you in some way, big or small. If it does, then let me know. I'd love to hear from you.

Enjoy,

Bart

About the Author

Bart Jacobs
Bart Jacobs

My name is Bart Jacobs and I run a mobile development company, Code Foundry. I’ve been programming for more than fifteen years, focusing on Cocoa development soon after the introduction of the iPhone in 2007.

Over the years, I’ve taught thousands of people about Swift and Cocoa development. Through my experience teaching, I’ve discovered and learned about the main problems people struggle with.

I created Cocoacasts to offer a roadmap for anyone interested in learning Swift and Cocoa development. Through Cocoacasts, I provide a clear path to learn the tools, the language, and the frameworks you need to master Swift and Cocoa development.

I currently work as a freelance developer and teach people about Swift and Cocoa development. While I primarily focus on developing software for Apple’s platforms, I consider myself a full stack developer with a love and interest for Swift and Ruby development.

You can find me on TwitterFollow me and say hi. You can also follow Cocoacasts on Twitter if you’re interested in what I teach on Cocoacasts.

Table of Contents

  • About Cocoacasts
  • Welcome
    • 1 Namespaces in Swift
    • 2 Dependency Injection in Swift
    • 3 Value Types and Reference Types
    • 4 Model-View-ViewModel in Swift
  • 1 Namespaces
    • Using Structures
    • Using Enumerations
    • Conclusion
  • 2 Dependency Injection
    • What Is Dependency Injection
    • An Example
    • Another Example
    • What Do You Gain
    • Types
    • A Word About Singletons
  • 3 Value Types and Reference Types
    • Value Types & Reference Types
    • An Example
    • Benefits of Value Types
    • When to Use Value Types
  • 4 Model-View-ViewModel
    • What Is It
    • Advantages
    • Problems
    • How Can We Solve This
    • MVVM in Practice

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub