RSSAmplifier

Blog

Cocoaphony

robnapier.netRSS feed ↗20 posts

Latest posts

A Mockery of Types

I’m going to talk about testing over the next few posts. If you’ve talked to me at any length over the last several years, you know I’ve been thinking a lot about testing, and I have somewhat unorthodox opinions. Unorthodox enough that I really haven’t wanted to write them down because I’m really not trying to start an argument. If your approach to testing works for you and your team, I think…

ASCII

Every part of this post is over-simplified. History is messy and difficult to sum up. The original version was twice as long and still over-simplified. Just go with it. Public Domain. Source: WikiCommons In 1961 the American Standards Association began developing a new character encoding to replace the dozens of existing systems. In the end they created the 7-bit system that we call the American…

AnyCodingKey

Let’s talk about CodingKey. It’s a protocol. It is not a magic enum thing. Coding keys do not have to be enums. There is some special compiler magic for when CodingKeys are enums, but it’s just a protocol. It’s something that wraps a string value, that may also wrap an int value. That’s it. public protocol CodingKey : CustomDebugStringConvertible , CustomStringConvertible , Sendable { var…

The Littlest Type

Sometimes there’s code so commonplace that we forget how strange it actually is. I mean, Swift is a strongly typed language right? Types types types! We say what things are, and the compiler enforces it for us. But then you see some piece of code like this: func addOne ( _ x : Int ) -> Int { fatalError ( "Haha! No Int for you!" ) } That’s legal Swift. I don’t think many would find that surprising.…

Protocols v: At Your Request

So, back to our APIClient . When last I left off , I had the following client code: final class APIClient { static let shared = APIClient () let baseURL = URL ( string : "https://www.example.com" ) ! let transport : Transport init ( transport : Transport = URLSession . shared ) { self . transport = transport } // Fetch any Fetchable type given an ID, and return it asynchronously func fetch < Model…

Protocols IV: That's Not a Number

So far in this series, I’ve created a simple APIClient that can fetch any Fetchable type and decode it from a specific API, and then extracted a Transport protocol to abstract away the network layer. In this part, I’ll reconsider the top of the stack, the models, and see if I can make those more flexible. The current models are User and Document: struct User : Codable , Hashable { let id : Int let…

Protocols III: Existential Spelling

This was supposed to be a quick sidebar, but it turned into a full-length article, so I’m calling it part 3. The original part 3, continuing the network stack, is mostly done, but I wanted to explain this weird word “existentials” first, and it turned out longer than I’d expected. Blame Joe Groff; he’s written too much interesting stuff lately and I want to talk about it. If you’re interested in…

Protocols II: A Mockery of Protocols

In the last section , I ended my little network stack at this point: // Something that can be fetched from the API protocol Fetchable : Decodable { static var apiBase : String { get } // The part of the URL for this type } // A client that fetches things from the API final class APIClient { let baseURL = URL ( string : "https://www.example.com" ) ! let session : URLSession = URLSession . shared //…

Protocols Sidebar I: Protocols Are Nonconformists

Last time , I mentioned something in passing: I need a new protocol. protocol Fetchable : Decodable { static var apiBase : String { get } } I need a protocol that requires that the type be Decodable, and also requires that it provide this extra string, apiBase . Read that again. It requires that the type be Decodable and also requires other things. I didn’t say that Fetchable is Decodable. It…

Protocols I: "Start With a Protocol," He Said

In the beginning, Crusty In 2015, at WWDC, Dave Abrahams gave what I believe is still the greatest Swift talk ever given, and certainly the most influential. ”Protocol-Oriented Programming in Swift,” or as it is more affectionately known, “The Crusty Talk.” This is the talk that introduced the phrase “protocol oriented programming.” The first time I watched it, I took away just one key phrase:…

A Conditional Breakpoint

I’m now a Conditional Breakpoint. It’s been a dream of mine for long time, and it finally happened at CocoaConf Chicago . There are folks who have played extensively with James Dempsey , and those are the Breakpoints. If you’ve only played occasionally (even once), you’re a Conditional Breakpoint. Originally, I wasn’t comfortable being a full “Conditional.” I’m not much of a guitarist. I can play…

Refactoring Slow and Steady

I’ve been talking with folks on a Slack about refactoring today, and I thought I’d put some of my thoughts here. Maybe a little less polished than I’d like, but I wanted to get them out of my head and down on “paper.” The conversation started by referencing the classic Joel piece, Things You should Never Do, Part I . Leading to my thoughts: Just finished some major refactoring work, moving ObjC to…

Talking and Teaching

Pedro Piñera makes some important points in his article In a world… . There are a number of things in there, and you should go read it, but I want to focus on one part, which is the observation that the core “iOS speaker circle” is a fairly small group of people. Pedro notes: There’s a huge difference when you compare a talk from someone that has been working a lot on the topic and from someone…

Copying

I’m on my way back from try! Swift , which was fantastic. Of course it had those obvious things I’d hope for. Interesting talks, friendly people. Making new friends, and reuniting with old ones. But it also had some surprising delights and lessons. I travel pretty well, but sometimes I make mistakes, and this was one of those times. The deodorant I thought I’d packed turned out to be body wash.…

Inspiration

As a speaker, writer, and member of our community, Daniel Steinberg is my inspiration. That’s not a secret. If you and I have spent much time talking after a conference, I’ve probably mentioned it. It’s not the sort of thing you usually say to someone, and I don’t think I ever have, but I’ve learned a lot from his speaking style, and I constantly try to live up to his standard of kindness. I’m not…

NSData, My Old Friend

Or… “How I learned to stop worrying, and love Foundation.” Forgive me, NSData. I was running around with that flashy [UInt8], acting like you didn’t have everything I need. I’ve learned my lesson. — Rob Napier (@cocoaphony) September 28, 2015 I did a lot of writing and rewriting of the Swift version of RNCryptor . I struggled especially with what type to use for data. I gravitated quickly to…

Type-erasure in Stdlib

When last we talked about type erasure , I described an easy way to build type erasures using closures. And I mentioned: (While this works exactly like AnySequence, this isn’t how AnySequence is implemented. In my next post I’ll discuss why and how to implement type erasers like stdlib does.) At the time I thought I’d pretty well nailed it down, but every time I dug into it I found another little…

RNCryptor V4

After months of writing and rewriting, I am happy to finally announce RNCryptor 4 beta 1 in Swift. RNCryptor 4 is a complete rewrite of RNCryptor for Swift 2 with full bridging support to Objective-C. It has a streamlined API, simpler installation, and improved internals. It continues to use the v3 data format and is fully interoperable with other RNCryptor implementations . For users desiring a…

A Little Respect for AnySequence

Once upon a time, when Swift was young, there were a couple of types called SequenceOf and GeneratorOf , and they could type erase stuff. “Type erase?” you may ask. “I thought we loved types.” We do. Don’t worry. Our types aren’t going anywhere. But sometimes we want them to be a little less…precise. In Swift 2, our little type erasers got a rename and some friends. Now they’re all named…

Product or Process?

Forgive a slight divergence. I’ll bring it back to software development before the end. A friend of mine is an arborist. He takes care of a large forest, trimming and culling trees. He’s quite good at it and enjoys it, but he’s worried about job security. He thinks cabinet making would be a good career move. He likes to work with wood, and high-end cabinets are very expensive so there’s clearly a…