<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[Some Kind Of Code]]></title><description><![CDATA[There is no perfect code]]></description><link>https://somekindofcode.com/</link><image><url>https://somekindofcode.com/favicon.png</url><title>Some Kind Of Code</title><link>https://somekindofcode.com/</link></image><generator>Ghost 5.82</generator><lastBuildDate>Sat, 11 Apr 2026 21:09:43 GMT</lastBuildDate><atom:link href="https://somekindofcode.com/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Handling Codable Parsing Errors]]></title><description><![CDATA[Stop API calls break your Swift code and learn how to prevent parsing errors when working with enums and arrays.]]></description><link>https://somekindofcode.com/handling-codable-parsing-errors/</link><guid isPermaLink="false">685a6a4399cc7a06b4b926c4</guid><category><![CDATA[guide:codables]]></category><category><![CDATA[Swift]]></category><dc:creator><![CDATA[Christopher Beloch]]></dc:creator><pubDate>Fri, 18 Jul 2025 20:11:14 GMT</pubDate><content:encoded><![CDATA[<p>Parsing data using the Decodable protocol can be easy but also annoying as it breaks on the smallest inconsistency or change in the API. For example if you use a property with an <code>enum</code>, your decoding will fail if the API adds a new case to it that is unknown by your Swift code. There are various ways to handle this without requiring an app update or new code deployment to prevent killing parts of your project for the users.</p><h2 id="example">Example</h2><p>For this article, I will use a simple example of a <code>News</code> model with a <code>source</code> property which the app will use to display the desired icon.</p><pre><code class="language-swift">enum NewsSource: String, Decodable {
  case someKindOfCode = &quot;skoc&quot;
  case swiftBlog = &quot;swift&quot;
}

struct News: Decodable {
  let title: String
  let excerpt: String
  let source: NewsSource
}</code></pre><pre><code class="language-js">[
  {
    &quot;title&quot;: &quot;Handling Codable Parsing Errors&quot;,
    &quot;excerpt&quot;: &quot;...&quot;,
    &quot;source&quot;: &quot;skoc&quot;
  },
  {
    &quot;title&quot;: &quot;Swift 6.1 Released&quot;
    &quot;excerpt&quot;: &quot;...&quot;,
    &quot;source&quot;: &quot;swift&quot;
  },
  {
    &quot;title&quot;: &quot;What&apos;s new in SwiftUI for iOS 26&quot;,
    &quot;excerpt&quot;: &quot;...&quot;,
    &quot;source&quot;: &quot;hackingwithswift&quot;
  }
]</code></pre><p>With the JSON above, the third item will cause a decoding error, because its <code>source</code> value can&apos;t be mapped to the defined enum cases in our model.</p><h2 id="not-a-solution-just-make-the-property-optional">Not a solution: Just make the property optional</h2><p>First of all what is NOT a simple solution: Making <code>source</code> optional. Just because the property is set to be optional, doesn&apos;t mean it will be <code>nil</code> on any decoding error. The valid values are just extended by the support for a non-existent key or a <code>null</code> value in JSON.</p><div class="kg-card kg-callout-card kg-callout-card-blue"><div class="kg-callout-emoji">&#x26A0;&#xFE0F;</div><div class="kg-callout-text">Please note, that for the sake of this article, I&apos;ll only include the decoding part. If your model is fully <code spellcheck="false" style="white-space: pre-wrap;">Codable</code>, please consider adding a custom encoding if necessary.</div></div><h2 id="solution-1-enum-fallback-case">Solution #1: Enum fallback case</h2><p>The first solution would be to create a fallback case, maybe with an associated enum that contains the original value. The later would require some additional code to resolve the original string values.</p><h3 id="simple-variant">Simple variant</h3><pre><code class="language-swift">enum NewsSource: String, Decodable {
  case someKindOfCode = &quot;skoc&quot;
  case swiftBlog = &quot;swift&quot;
  case unknown

  init(from decoder: Decoder) throws {
    let container = try decoder.singleValueContainer()
    let value = try container.decode(String.self)

    // Try to use the raw value initializer.
    // If that doesn&apos;t succeed, fallback to the unknown case
    self = .init(rawValue: value) ?? .unknown
  }
}</code></pre><h3 id="associated-value-variant">Associated value variant</h3><p>Based on the simple variant from above, we could also add an associated value to the unknown case. With that we&apos;ll be able to debug, log or even display that value easily.</p><pre><code class="language-swift">// Note the removed String conformance
enum NewsSource: Decodable { 
  case someKindOfCode
  case swiftBlog
  case unknown(String)
    
  init(from decoder: any Decoder) throws {
    let container = try decoder.singleValueContainer()
    let value = try container.decode(String.self)
        
    switch value {
    case &quot;skoc&quot;:
      self = .someKindOfCode
    case &quot;swift&quot;:
      self = .swiftBlog
    default:
      self = .unknown(value)
    }
  }
}</code></pre><h2 id="solution-2-gracefully-failed-parsing">Solution #2: Gracefully failed parsing</h2><p>Another solution that I prefer is to drop incompatible data. With this solution you loose SOME data, but won&apos;t kill your feature entirely.</p><p><a href="https://gist.github.com/CBeloch/3344fe59aebdd823af5921ba4967f66b?ref=somekindofcode.com" rel="noreferrer">I created a wrapper</a> that will drop all the elements that can&apos;t be decoded successfully, but still makes the decoding errors accessible. With this solution, the news from a new source wouldn&apos;t be displayed until we got an update, but it will still display the other items.</p><p>You can use it in two ways.</p><h3 id="array-replacement">Array replacement</h3><p><code>LossySequence</code> is still conforming to the <code>Sequence</code> protocol and can mostly be used as a replacement for an array and your decoding would look like this:</p><pre><code class="language-swift">let news = try decoder.decode(LossySequence&lt;News&gt;.self, from: data)
news.errors // contains an array of errors that happened during decoding
news.forEach { singleNews in 
  // do sth with singleNews
}</code></pre><h3 id="property-wrapper">Property Wrapper</h3><p>The easiest way is to use it as a property wrapper.</p><p>Image we have a little different response from our API that has the news items nested in it:</p><pre><code class="language-js">{
  &quot;news&quot;: [],
  &quot;paging&quot;: {}
}</code></pre><p>The corresponding model could look like this:</p><pre><code class="language-swift">struct NewsResponse: Decodable {
  @LossySequence
  var news: [News]
  let paging: Paging
}</code></pre><p>To access the errors, you now have to access the projected value using <code>$</code>:</p><pre><code class="language-swift">let response = try JSONDecoder().decode(NewsResponse.self, from: data)
response // NewsResponse
response.news // Now a real array
response.$news // The LossySequence object
response.$news.error // The error array</code></pre><h2 id="summary">Summary</h2><p>Both ways are legit solutions and depend on your desired outcome. I personally mix both of them. For our news example, solution #1 would be better, as we would simply need a fallback UI for the <code>.unknown</code> case. But as we could encounter many other sources for decoding errors, solution #2 could be considered as well and used in all the places where you have to decode a list of data.</p>]]></content:encoded></item><item><title><![CDATA[Generating an API SDK]]></title><description><![CDATA[Being tired of writing all the endpoint and model declarations for a new projects, I went down the rabbit hole of generating an SDK based on a swagger documentation]]></description><link>https://somekindofcode.com/generating-a-api-sdk/</link><guid isPermaLink="false">62f13c35fa836555d9f5c7ca</guid><category><![CDATA[iOS]]></category><category><![CDATA[Swift]]></category><category><![CDATA[general]]></category><dc:creator><![CDATA[Christopher Beloch]]></dc:creator><pubDate>Mon, 14 Nov 2022 12:07:37 GMT</pubDate><media:content url="https://somekindofcode.com/content/images/2022/11/2022-11-openapi-to-sdk.png" medium="image"/><content:encoded><![CDATA[<img src="https://somekindofcode.com/content/images/2022/11/2022-11-openapi-to-sdk.png" alt="Generating an API SDK"><p>A few weeks ago, I began working on a new project. Instead of working together with a team of web developers and designing all APIs from scratch, the server API was already available as we had to connect to the existing service of our client. A brief look at the API documentation revealed, that I have no desire in writing all the models and calls from scratch. As the documentation also had an interactive version supported by <a href="http://swagger.io/?ref=somekindofcode.com">Swagger</a>, including a <code>swagger.json</code> file that is a nice representation of all the models and APIs and the corresponding data that you&apos;ll have to send and receive, I took a dive into tools that could generate some kind of an SDK for the project.</p><p>I aimed for the following requirements:</p><ul><li>generate models and API definitions from <code>swagger.json</code></li><li>customizable templates</li><li><em>optional</em>: multiple templates to support multiple platforms</li></ul><p>I was expecting that I have to write my own tool. If I had to, I would probably go with Node.js, TypeScript, and the <a href="https://www.npmjs.com/package/@apidevtools/swagger-parser?ref=somekindofcode.com">@apidevtools/swagger-parser</a> package.</p><p>But after <a href="https://twitter.com/SomeKindOfCode/status/1544238176126083075?ref=somekindofcode.com">asking on Twitter</a> I got pointed at the <a href="https://github.com/swagger-api/swagger-codegen?ref=somekindofcode.com">Swagger Codegen</a> project. It is Java-based and I had no intention to install Java on my system. At least you can execute the CLI via <a href="https://www.docker.com/?ref=somekindofcode.com">Docker</a> and the <a href="https://hub.docker.com/r/swaggerapi/swagger-codegen-cli/?ref=somekindofcode.com">official container</a>. You only have to write and compile Java code if you want to create a complete custom generator. But as they already provide a lot of templates, including a <code>swift5</code> template, I gave that one a shot.</p><h2 id="swagger-codegen">Swagger Codegen</h2><p>The models are fine as they are. Structs conforming to <code>Codable</code> with optionally generated <code>CodingKeys</code>, all properties available, and even an initializer for all the properties. Everything <code>public</code> and ready to be used as a dedicated package. Well... almost.</p><p>The API files are what I was most concerned about. These will require customization from my side and I knew this before I started searching for solutions. But I wanted to see what the default output looks like.</p><p>The <code>swift5</code> template at its core requires <a href="https://github.com/Alamofire/Alamofire?ref=somekindofcode.com">Alamofire</a> and can be extended to support <a href="https://github.com/mxcl/PromiseKit?ref=somekindofcode.com">PromiseKit</a> and/or <a href="https://github.com/ReactiveX/RxSwift?ref=somekindofcode.com">RxSwift</a>. I don&apos;t need any of these dependencies at the moment and the generated code comes with a bit of boilerplate code that I don&apos;t need as well. Luckily there is an option to only generate the API and model files.</p><pre><code class="language-bash">-Dmodels -Dapis</code></pre><p>Customizing the template is as easy as creating my own template directory and naming the templates the same way, the generator (<a href="https://github.com/swagger-api/swagger-codegen-generators/tree/master/src/main/resources/handlebars/swift5?ref=somekindofcode.com">click here for the swift5 generator files</a>) uses them. Swagger Codegen uses <a href="http://mustache.github.io/?ref=somekindofcode.com">mustache</a> templating. The V3 Variant uses the <a href="https://github.com/jknack/handlebars.java?ref=somekindofcode.com">Java implementation of Handlebars</a> which is compatible with existing mustache templates. Documentation on the official sites is fine, but if you don&apos;t want to touch the Java code of the generators like me, you are stuck with the features the used libraries provide. And I got stuck pretty early: There is no option to lowercase or uppercase a value. At least I haven&apos;t found one without manipulating the generators java files and registering the <code><a href="https://github.com/jknack/handlebars.java/blob/master/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java?ref=somekindofcode.com">StringHelpers</a></code> that are available in the Handlebars Java implementation but have to be enabled manually.</p><p>This at the moment keeps me from using the Swagger Codegen project, but luckily there is an alternative by OpenAPI called the <a href="https://openapi-generator.tech/?ref=somekindofcode.com">OpenAPI Generator</a>. As Swagger makes use of the OpenAPI specifications this could work.</p><h2 id="next-try-openapi-generator">Next try: OpenAPI Generator</h2><p>It uses Java as well and a <a href="https://hub.docker.com/r/openapitools/openapi-generator-cli?ref=somekindofcode.com">Docker container</a> is available, too. And most important: A <a href="https://openapi-generator.tech/?ref=somekindofcode.com">full-fledged documentation</a> website including a section about <a href="https://openapi-generator.tech/docs/templating?ref=somekindofcode.com">modifying and writing templates</a> and even <a href="https://openapi-generator.tech/docs/generators/swift5?ref=somekindofcode.com">the options of the </a><code><a href="https://openapi-generator.tech/docs/generators/swift5?ref=somekindofcode.com">swift5</a></code><a href="https://openapi-generator.tech/docs/generators/swift5?ref=somekindofcode.com">-generator</a>. </p><p>The OpenAPI Generator uses basically the same logic as the Swagger Codegen project, but templates have a few more extensions to use in the mustache templates. These extended functions are called <code>lambdas</code>. These are neatly documented in the templating documentation I linked above.</p><p>As lambdas for uppercase and lowercase are available, I began customizing the output. I only had to create my own version of the <code>api.mustache</code> file inside my own template folder. As a reference, I used the <a href="https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/swift5/api.mustache?ref=somekindofcode.com">original file</a> to get to know about all the properties and the templating syntax.</p><p>You can use the same command line parameter as for Swagger Codegen above to only generate API and model files. I ended up adding some of my own support files and customized the output by using a &#xA0;<code>config.yml</code> and told the CLI to use it. Of course, <a href="https://openapi-generator.tech/docs/customization?ref=somekindofcode.com">there is documentation</a>.</p><pre><code class="language-bash">-c &lt;path to config.yml&gt;</code></pre><p>I disabled all the other files and ended up with a config like this:</p><pre><code class="language-yml">templateDir: /local/templates/swift-customized
projectName: MyAPI
useBacktickEscapes: true
useJsonEncodable: false 
files:
  StringRepresentation.swift:
    folder: MyAPI/Classes/OpenAPIs
  JSONEndpoint.swift:
    folder: MyAPI/Classes/OpenAPIs
  XcodeGen.mustache: 
    folder: unused
  APIHelper.mustache:
    folder: unused
  APIs.mustache:
    folder: unused
  CodableHelper.mustache:
    folder: unused
  Cartfile.mustache:
    folder: unused
  Configuration.mustache:
    folder: unused
  Extensions.mustache:
    folder: unused
  JSONDataEncoding.mustache:
    folder: unused
  JSONEncodingHelper.mustache:
    folder: unused
  Models.mustache:
    folder: unused
  OpenISO8601DateFormatter.mustache:
    folder: unused
  Podspec.mustache:
    folder: unused
  README.mustache:
    folder: unused
  SynchronizedDictionary.mustache:
    folder: unused
  URLSessionImplementations.mustache:
    folder: unused 
  gitignore.mustache:
    folder: unused 
  git_push.sh.mustache:
    folder: unused 
  api_doc.mustache:
    folder: unused </code></pre><p>What I did was move everything that I don&apos;t need into a folder called <code>unused</code> and added my custom files to the target location at the top. As you can see, I will not use the <code>Podspec</code> or <code>Cartfile</code> templates, as we only use Swift Package Manager at this stage.</p><p>As I created a small shell script to run the generator, I added a few lines to delete the <code>unused</code>-folder after generating everything and also used <a href="https://github.com/nicklockwood/SwiftFormat?ref=somekindofcode.com">SwiftFormat</a> at the end, because writing the templates with a good output formatting was way harder than I thought.</p><h2 id="it-is-only-as-good-as-the-documentation">It is only as good as the documentation</h2><p>Over the time of regenerating and using the generated code in the project, my colleague and I have noticed that sometimes the attributes of the models got moved around which resulted in a different parameter order for the initializer of that model. This of course ended up messing with the code where we created our own instances as input to an API.</p><p>This happened because the swagger generator on the server side messed it up on a few models over time. To fix that, I added a python script to sort all the keys of the <code>swagger.json</code> before passing it to the OpenAPI Generator.</p><p>Some data types have been messed up like a <code>Date</code> response type was documented as <code>Int</code>, but that could be fixed after <a href="https://swagger.io/docs/specification/data-models/data-types?ref=somekindofcode.com">editing the documentation header</a> on the server side.</p><h2 id="creating-a-script">Creating a script</h2><p>As I have mentioned above, I did a bunch of extra stuff to get an output I was satisfied with.</p><ol><li>Download the <code>swagger.json</code> from the server</li><li>Sort the JSON</li><li>Run the generator via docker</li><li>cleanup output</li><li>format output</li></ol><p>Your mileage may vary depending on your server-side documentation generator and the output SDK language you use.</p><p>My shell script for the Swift output looked like this at the end:</p><pre><code class="language-bash">LANGUAGE=&quot;swift5&quot;
SOURCE=&quot;https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore-expanded.json&quot;
SOURCE_DUMP_FILE=&quot;swagger.json&quot;

# 1. download swagger.json
curl $SOURCE &gt; $SOURCE_DUMP_FILE

# 2. sort swagger json to sort model properties
python3 jsonSort.py $SOURCE_DUMP_FILE

# 3. generate SDK
docker run 
  --rm \
  -v &quot;${PWD}:/local&quot; \ # link current folder to /local in the container
  openapitools/openapi-generator-cli generate \
  -i /local/$SOURCE_DUMP_FILE \
  -g $LANGUAGE \
  -o &quot;/local/out/$LANGUAGE&quot; \
  -c /local/config-iOS.yaml

# 4. Cleanup unused files
rm -r &quot;${PWD}/out/$LANGUAGE/unused&quot;
rm -r &quot;${PWD}/out/$LANGUAGE/docs&quot;
rm -r &quot;${PWD}/out/$LANGUAGE/.openapi-generator&quot;
rm &quot;${PWD}/out/$LANGUAGE/.openapi-generator-ignore&quot;
rm &quot;${PWD}/out/$LANGUAGE/.swiftformat&quot;

# 5. Swift Format
if which swiftformat &gt;/dev/null; then
  swiftformat &quot;${PWD}/out/$LANGUAGE/&quot;
else
  echo &quot;warning: swiftformat not installed.&quot;
  echo &quot;Install via&quot;
  echo &quot;\tbrew install swiftformat&quot;
fi</code></pre><p>Feel free to modify it to your needs.</p><h2 id="summary">Summary</h2><p>It was a bit of work to learn the templating syntax and find out about the parameters and properties to use. But looking at the original templates helped a lot.</p><p>The project where I used this generator had over 30 Endpoints and over 200(!) models. Writing all these by hand would&apos;ve been madness. And they changed in some spots over time. Some of the model files are not even used, because abstract model definitions are treated as a regular model. For example, we have an abstract <code>DatabaseObject</code> model, that has an <code>id</code>, <code>createdAt</code> and <code>updatedAt</code> field and it is the base for most of the models. This, in my case, will generate a corresponding Swift model, but the other models are not a subclass of this model. They still have the properties on their own, but in the code, we will never refer to the <code>DatabaseObject</code> model.</p><p>In some places, it would&apos;ve been cool to use the abstract definitions as a protocol, but I didn&apos;t find a neat way to realize it. But you can always create a few extensions by hand if you need them. We tried never to hack the generated files and keep the output as clean as possible. Any extension happened separately from the API Package. </p><p>All the time I used to modify everything to our needs was nothing compared to the time this saved us now and will in the future as this reconfiguration for our architecture can be reused very easily for any future project.</p>]]></content:encoded></item><item><title><![CDATA[Codables: (De)Serializing - Ch. 2: Coding Keys]]></title><description><![CDATA[In the second chapter of customizing the (de)serialization logic of Codables, we take a look at the CodingKeys]]></description><link>https://somekindofcode.com/codables-de-serializing-ch-2-coding-keys/</link><guid isPermaLink="false">5d4835cdddbad007d5522fdf</guid><category><![CDATA[guide:codables]]></category><category><![CDATA[Swift]]></category><dc:creator><![CDATA[Christopher Beloch]]></dc:creator><pubDate>Sun, 05 Jan 2020 09:00:00 GMT</pubDate><media:content url="https://somekindofcode.com/content/images/2020/01/03---Coding-Keys---Cover-Code.png" medium="image"/><content:encoded><![CDATA[<img src="https://somekindofcode.com/content/images/2020/01/03---Coding-Keys---Cover-Code.png" alt="Codables: (De)Serializing - Ch. 2: Coding Keys"><p>CodingKeys are created to map data between your model and the data. These are mostly created as an enum to easily map the data in a custom decoding or encoding logic. If you don&apos;t declare the keys yourself, the compiler will do this automatically for you. But as we want to map data differently we will to this on our own now.</p><p>An object that defines the coding keys has to conform to the protocol <code>CodingKey</code> (no s). This has to have two initializers: One <code>init?(intValue: Int)</code> and `init?(stringValue: String)` with corresponding properties <code>var intValue: Int? { get }?</code> and <code>var stringValue: String { get }</code> <em>(<a href="https://developer.apple.com/documentation/swift/codingkey?ref=somekindofcode.com">Apple Documentation</a>)</em>. As you can see, <code>stringValue</code> is not optional. This is because the keys of a dictionary use strings in most cases or can be at least converted to a string. Arrays are automatically handled by iterating the data and don&apos;t require a coding key for each index.</p><p>The easiest way to conform to this protocol is to use an enum with a defined <code>RawValue</code> and this is what I&apos;ll use in my example.</p><p>This will be our input JSON for now:</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">{
    &quot;id&quot;: &quot;5A30CB22-76C8-4A2D-A86E-5AB181DD5838&quot;,
    &quot;username&quot;: &quot;CBeloch&quot;,
    &quot;age&quot;: 30
}
</code></pre>
<!--kg-card-end: markdown--><p>Let&apos;s take our example from above and map <code>id</code> of the incoming data to our property called <code>identifier</code>.</p><!--kg-card-begin: markdown--><pre><code class="language-swift">struct User {
    let identifier: String
    let username: String
    let age: Int
}

// MARK: Codable

extension User: Codable {
    private enum CodingKeys: String, CodingKey {
        case identifier = &quot;id&quot;
        case username
        case age
    }
}
</code></pre>
<!--kg-card-end: markdown--><p>And thats it! The enum has a <code>String</code> as <code>RawValue</code> type and we set the value of the <code>identifier</code> case to `&quot;id&quot;`. The raw values for <code>username</code> and <code>age</code> are automatically generated, based on their name. The important part is, that the names for the keys have to match the property names and that you add a key for <strong>all</strong> of your properties. </p><p>You can restrict access to the <code>CodingKeys</code> by setting them to <code>private</code> so you can&apos;t access the keys from the outside by using <code>User.CodingKeys</code>.</p><p><em>In the next chapter I&apos;ll show you how to write your own decoder logic for your model which will be an initializer. In that chapter, naming of the CodingKeys enum and naming of the keys will not matter anymore.</em></p>]]></content:encoded></item><item><title><![CDATA[Codables: (De)Serializing - Ch. 1: Coder Options]]></title><description><![CDATA[The first chapter to customize your Codable (de)serialization is about the options of your selected Decoder and Enc​oder.]]></description><link>https://somekindofcode.com/codables-coder-options/</link><guid isPermaLink="false">5d1a1c3254a52507e2ecbefe</guid><category><![CDATA[guide:codables]]></category><category><![CDATA[Swift]]></category><dc:creator><![CDATA[Christopher Beloch]]></dc:creator><pubDate>Tue, 02 Jul 2019 07:52:54 GMT</pubDate><media:content url="https://somekindofcode.com/content/images/2019/07/02---Coder-Options---Cover-Code.png" medium="image"/><content:encoded><![CDATA[<img src="https://somekindofcode.com/content/images/2019/07/02---Coder-Options---Cover-Code.png" alt="Codables: (De)Serializing - Ch. 1: Coder Options"><p>Most of our (De-) Serializing work is done by Codables themself. All keys of the data structure are mapped directly to the property names of your model. Without any modification to the naming. But in most cases you want to optimize the data in a way that works better for you.</p><p>At first you should check out what options your Coder gives you that could already fix a lot of your issues with the naming of the API and your model properties.</p><h2 id="keydecodingstrategy">keyDecodingStrategy</h2><p>The <code>JSONDecoder</code> for example has a <code>keyDecodingStrategy</code> property which can be set to <code>.useDefaultKeys</code> <em>(default) </em>or <code>.convertFromSnakeCase</code>. This fixes the &#xA0;issues that you get a <code>snake_case</code> (words separated by underscores) property from an API, but you want your model properties to be <code>camelCase</code> (words separated by uppercasing the first letter of the new word). This is also available on the <code>JSONEncoder</code> with equivalent naming of <code>keyEncodingStrategy</code> and <code>.convertToSnakeCase</code>.</p><h2 id="data-and-date-conversion">Data and Date conversion</h2><p>And the JSON Coders have strategy options for <code>Data</code> and <code>Date</code> conversion. The properties for this are named <code>dataEncodingStrategy</code> and <code>dateEncodingStrategy</code> for the</p><p><code>Data</code> is converted from and to Base64 by default and <code>Date</code> will be encoded by it&apos;s own encoding/decoding logic by default (<code>.deferredToDate</code>). But the strategy can be changed to <code>.iso8601</code> which creates/parses an <a href="https://en.wikipedia.org/wiki/ISO_8601?ref=somekindofcode.com">ISO 8601</a> compatible string, <code>.formatted(DateFormatter)</code> which takes a custom <a href="https://developer.apple.com/documentation/foundation/dateformatter?ref=somekindofcode.com"><code>DateFormatter</code></a> or if you are more into UNIX timestamps: <code>.secondsSince1970</code> and <code>.millisecondsSince1970</code>.</p><p>All of these strategy options also have a <code>.custom</code> option. More on that in a later chapter when we get into ValueContainer. <em>(A Link will follow as soon as the article is online)</em></p><blockquote><em>A short annotation if you are using a PHP based backend for your app:</em>&#x200C;&#x200C;<em>&#x200C;&#x200C;PHP does have an option to encode a </em><code><a href="https://www.php.net/manual/de/class.datetime.php?ref=somekindofcode.com">DateTime</a></code><em> object to ISO 8601 and it works fine on the decoding side of your app. But if you want to send a Date whereas you have to encode it to an ISO 8601 string, this doesn&apos;t work in most cases. That&apos;s because PHP isn&apos;t conforming to the standard and uses a default format of &#xA0;</em><code><em>&quot;Y-m-d\TH:i:sO&quot;</em></code><em> (</em><a href="https://www.php.net/manual/de/class.datetimeinterface.php?ref=somekindofcode.com"><em>Source</em></a><em>) - The </em><code><em>O</em></code><em> indicates a timezone like </em><code><em>+0100</em></code><em>, but </em><code><em>Z</em></code><em> is valid for UTC timezone by ISO 8601 definition, but PHP throws an error if it gets such a date string for parsing.&#x200C;&#x200C;&#x200C;&#x200C;Use a </em><code><em>.formatted(DateFormatter)</em></code><em> strategy and use </em><code><em>&quot;yyyy-MM-dd&apos;T&apos;HH:mm:ssxxxx&quot;</em></code><em> as your </em><code><em>dateFormat</em></code><em> on the app side.</em></blockquote><p>This is it for the Coder options. At least for the JSON Coder provided by the Swift Standard Library. The <code>PropertyListEncoder</code> only has an option for the output format. If you want the encoded data to be binary, xml or openStep formatted. The corresponding decoder has no options at all.</p><p>Additional note: Both the JSON and PropertyList Encoder and Decoder are available on Linux as well.</p><p>There are 3rd party Encoder and Decoder out there, just check their documentation on how to modify their logic. Maybe this options will already help you a lot.</p><h2 id="references">References</h2><!--kg-card-begin: markdown--><ul>
<li>JSON
<ul>
<li><a href="https://developer.apple.com/documentation/foundation/jsondecoder?ref=somekindofcode.com">JSONDecoder</a></li>
<li><a href="https://developer.apple.com/documentation/foundation/jsonencoder?ref=somekindofcode.com">JSONEncoder</a></li>
</ul>
</li>
<li>Property List
<ul>
<li><a href="https://developer.apple.com/documentation/foundation/propertylistdecoder?ref=somekindofcode.com">PropertyListDecoder</a></li>
<li><a href="https://developer.apple.com/documentation/foundation/propertylistencoder?ref=somekindofcode.com">PropertyListEncoder</a></li>
</ul>
</li>
<li>3rd Party
<ul>
<li><a href="https://github.com/hirotakan/MessagePacker?ref=somekindofcode.com">MsgPack</a></li>
<li><a href="https://github.com/MaxDesiatov/XMLCoder?ref=somekindofcode.com">XML</a></li>
</ul>
</li>
</ul>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Codables: The Basics]]></title><description><![CDATA[Codables are a very useful tool if you need to decode from or to different formats like JSON. Get your introduction into Codables here.]]></description><link>https://somekindofcode.com/codables-the-basics/</link><guid isPermaLink="false">5cb0bbf40890b72f11aa2812</guid><category><![CDATA[guide:codables]]></category><category><![CDATA[Swift]]></category><dc:creator><![CDATA[Christopher Beloch]]></dc:creator><pubDate>Sun, 28 Apr 2019 06:04:00 GMT</pubDate><media:content url="https://somekindofcode.com/content/images/2019/04/01---Basics---Cover-Code-1.png" medium="image"/><content:encoded><![CDATA[<img src="https://somekindofcode.com/content/images/2019/04/01---Basics---Cover-Code-1.png" alt="Codables: The Basics"><p>It has been a long time we used stuff like <code>NSJSONSerialization</code> or <code>NSPropertyListSerialization</code> and dropped the <code>NS</code> prefix in favor of Swift. It helped converting data from or to JSON / Property List. Creating an instance of your model classes or serialize them to one of the formats would require writing a lot of additional code to convert the values to the correct data types.</p><p>Well, the time of these has come to an end and since Swift 4 we got a hand full of new protocols that allow the compiler to generate all the necessary code in the background. But we will still be able to customize the behaviours. More on that in a later chapter. Let us begin with the basics.</p><h2 id="the-protocols">The Protocols</h2><p>There are only two (or three) protocols that you really have to care about: <code>Decodable</code> and <code>Encodable</code>. And <code>Codable</code>, but that is only a type alias for <code>Decodable &amp; Encodable</code> so it is just a simpler annotation when you want a model do be de- and encodable.</p><h3 id="decodable">Decodable</h3><p>This is the protocol when you want to decode data to your model. When you work with external Web-APIs which are JSON, you will most likely use <code>Decodable</code> to work with you model within your app.</p><h3 id="encodable">Encodable</h3><p>For the serialization part, meaning you want to store your model data in a file or send it out to an API, <code>Encodable</code> is you protocol of choice. </p><h2 id="codable-conformant-types">Codable conformant types</h2><p>Most of the data types you get from the Swift Standard Library are conformant to <code>Decodable</code> and <code>Encodable</code>. You can find a complete list in the <a href="https://developer.apple.com/documentation/swift/decodable?ref=somekindofcode.com#conforming-types">documentation provided by Apple</a>. I linked the conformant types for <code>Decodable</code>, but all of these types also work for Encodable.</p><p>As you can see, event objects like <code>CGPoint</code> and <code>CGSize</code> are listed and completly conform to the <code>Codable</code> protocol. But they are represented as an array of float values. <code>CGRect</code> is represented as an array of arrays with float values. This may not be the ideal way of &#xA0;representing the data, but it could be enough if you just want to store data in a local file instead of accessing a self-explaining API.</p><p><code>Date</code> and <code>Data</code> are special snowflakes in the Codable space. At least if you want to use a JSONDe-/Encoder. These Coders special settings to modify the strategy on how a Date will be (de-)serialized. ISO-8601 formatted? UNIX timstamp? No problem at all. You can even add your own strategy. More on this in a later chapter.</p><h2 id="example">Example</h2><p><em>For convenience I will mostly use JSON in my examples because it is more readable than a full fledged property list.</em></p><p>Lets take this product list as a short example to introduce you to Codables:</p><!--kg-card-begin: markdown--><pre><code class="language-swift">let jsonString = &quot;&quot;&quot;
[{
  &quot;title&quot;: &quot;Awesome new Book&quot;,
  &quot;price&quot;: 12.99,
  &quot;currency&quot;: &quot;EUR&quot;
},{
  &quot;title&quot;: &quot;Fantastic Movie&quot;,
  &quot;price&quot;: 9,
  &quot;currency&quot;: &quot;USD&quot;
}]
&quot;&quot;&quot;
</code></pre>
<!--kg-card-end: markdown--><p>Our goal is to parse this data that can be extended in the future and work with a <code>Product</code> model within my app.</p><h2 id="model">Model</h2><!--kg-card-begin: markdown--><pre><code class="language-swift">struct Product: Codable {
    let title: String
    let price: Double
}
</code></pre>
<!--kg-card-end: markdown--><p>Let us leave out the <code>currency</code> property at this step. We get back to it in a minute.</p><h2 id="decode-json">Decode JSON</h2><p>To decode our <code>jsonString</code>, we have to convert it to a <code>Data</code> object</p><!--kg-card-begin: markdown--><pre><code class="language-swift">let jsonData: Data = Data(jsonString.utf8)
</code></pre>
<!--kg-card-end: markdown--><p><em>I&apos;m doing it this way, because <code>jsonString.data(using: .utf8)</code> would result in an optional Data (<code>Data?</code>) type and I don&apos;t want to unwrap it and force unwraps are my most hated lines of code.</em></p><p>As we use JSON in our example, we need a <code>JSONDecoder</code> that is happily provided by Swift. Most decoders have a simple <code>func decode(_:from:)</code> function.</p><!--kg-card-begin: markdown--><pre><code class="language-swift">let decoder = JSONDecoder()

do {
    let deserializedData = try decoder.decode(Array&lt;Product&gt;.self, from: jsonData)
} catch {
    print(&quot;Decoding Error&quot;, error)
}
</code></pre>
<!--kg-card-end: markdown--><p><code>deserializedData</code> is now from type <code>Array&lt;Product&gt;</code> or <code>[Product]</code> if you like the later one more.</p><p>If the decoding fails, you&apos;ll get an error explaining what went wrong and where. Like a key that is missing or was the wrong data type.</p><h2 id="recursive-de-encoding">Recursive De-/Encoding</h2><p>As I mentioned above, I left the currency value out of the model. Thats because I would like to implement this as an <code>enum</code>. You can add any other type to your model as they are recursively conformant to the same Codable protocols. This means that as our <code>Product</code> model is <code>Codable</code>, our enum has to be <code>Codable</code> as well.</p><h2 id="enums">Enums</h2><p>For an enum to be En- and/or Decodable, it has to have a raw value if we don&apos;t want to write the logics for (de)serializing the object. <em>We will come to that in a later, more advanced guide.</em> </p><p>Lets add our currency enum:</p><!--kg-card-begin: markdown--><pre><code class="language-swift">struct Product: Codable {
    let title: String
    let price: Double
    let currency: Currency // added the property
}

enum Currency: String, Codable {
    case usDollar = &quot;USD&quot;
    case euro = &quot;EUR&quot;
}
</code></pre>
<!--kg-card-end: markdown--><p>This is it. We now have a <code>currency</code> property with an enum. One thing to notice: Any other value (like <code>&quot;GBP&quot;</code>) will cause the deserialization to fail! And the most sad part is that <strong>it will also fail when</strong> you set currency to be <strong>an optional value</strong>.</p><h2 id="encode-json">Encode JSON</h2><p>Encoding works just like decoding. Just instead of a <code>JSONDecoder</code> we use a <code>JSONEncoder</code>:</p><!--kg-card-begin: markdown--><pre><code class="language-swift">let encoder = JSONEncoder()
do {
    // deserializedData contains our Product array
    let serializedProductsData: Data = try encoder.encode(deserializedData)
    
    // Convert Data to String
    let serializedProductsString: String = String(data: serializedProductsData, encoding: .utf8)
} catch {
    print(&quot;Encoding Error&quot;, error)
}
</code></pre>
<!--kg-card-end: markdown--><p>At this stage we could also convert the data to a plist by using a <code>PropertyListEncoder</code>.</p><p><em>Please note, that you&apos;ll lose all properties on the encoding side that hadn&apos;t been parsed on the decoding side. If you use the example without the </em><code>currency</code> property, the encoding will drop that, too.</p><h2 id="wrap-it-up">Wrap it up</h2><p>I hope you got a little insight in how to work with Codables without using any Frameworks or fancy code. We will get into it and dive a little deeper in the next guides around this topic and how to handle stuff like the enum issue above and how to work with annoying APIs that you can streamline a little bit with Codables.</p><p>I will explain how to write custom (de)serialization for your models and how to solve some issues that can occur.</p>]]></content:encoded></item><item><title><![CDATA[WatchConnectivity and App Lifetime]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>I&apos;m currently playing around with watchOS and communicating with the main iOS App.<br>
The basic and easiest way since watchOS 2 and iOS 9 is to use the <code>WatchConnectivity</code> Framework provided by Apple.</p>
<p>It&apos;s very simple by using the <code>WCSession</code> instance you can access by <code>WCSession.</code></p>]]></description><link>https://somekindofcode.com/watchconnectivity-and-app-lifetime/</link><guid isPermaLink="false">5b8f793525f30638fbf0c079</guid><category><![CDATA[iOS]]></category><category><![CDATA[watchOS]]></category><dc:creator><![CDATA[Christopher Beloch]]></dc:creator><pubDate>Tue, 18 Jul 2017 08:28:44 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>I&apos;m currently playing around with watchOS and communicating with the main iOS App.<br>
The basic and easiest way since watchOS 2 and iOS 9 is to use the <code>WatchConnectivity</code> Framework provided by Apple.</p>
<p>It&apos;s very simple by using the <code>WCSession</code> instance you can access by <code>WCSession.default</code> and assign a delegate of the <code>WCSessionDelegate</code> to it and activate the session on the watchOS and iOS side.</p>
<p>To pass data between the devices, you can use the following methods:</p>
<pre><code class="language-swift">func updateApplicationContext(_ applicationContext: [String : Any]) throws

func sendMessage(_ message: [String : Any], replyHandler: (([String : Any]) -&gt; Void)?, errorHandler: ((Error) -&gt; Void)? = nil)
func sendMessageData(_ data: Data, replyHandler: ((Data) -&gt; Void)?, errorHandler: ((Error) -&gt; Void)? = nil)
</code></pre>
<p>The application context is a shared context between the devices and can directly be accessed by the corresponding property of the <code>WCSession</code> instance.</p>
<p>Now we get to my use-case: I wanted to transfer the workout-data (heartbeats per minute) from my watch to the phone as fast as possible. I maybe could grab them directly from HealthKit, but I didn&apos;t went that way and <strong>wanted direct messaging</strong> between my Apple Watch and my iPhone.<br>
The second thing I wanted to achieve was to <strong>wake up the iOS App</strong> when I have data to send from the watch so I don&apos;t have to care about that one being launched as well.</p>
<p>To achieve this, you can&apos;t use the application context. This only works during runtime. The best way is to use the <code>sendMessage</code> methods (the data and/or dictionary version depending on your personal use-case).</p>
<p>In my use-case the watchOS-side is sending a dictionary message and triggers the iOS app to wake up and I further analyzed the lifetime on the app side.</p>
<p>I logged when the app <code>didFinishLaunchingWithOptions</code>, <code>applicationDidBecomeActive</code>, and when my first view controller was loaded and a message received.</p>
<p>This is a regular app launch:</p>
<pre><code class="language-text">App launched
View Controller loaded
App did become active
</code></pre>
<p>And this was the log when I send a message from watchOS:</p>
<pre><code class="language-text">App launched
View Controller loaded
got message
</code></pre>
<p>The only thing missing was the <code>applicationDidBecomeActive</code>, but everything else worked as intended and I even got the full first view controller I can work with.<br>
As I was sending messages periodically like every 5 seconds, the app was kept alive for some time, but <strong>didn&apos;t terminate</strong> and also doesn&apos;t move to the background, because it already is. Even after some time of not sending any messages. I logged <code>applicationWillResignActive</code>, <code>applicationDidEnterBackground</code> and <code>applicationWillTerminate</code> for this and none of them got triggered.</p>
<p>I hope this information can help some people in designing a code structure for their app without having to run these kind of tests on their own.</p>
<p style="text-align: center; font-size: small;"><em>This was testet using Xcode 9, iOS 11 and watchOS 4 in Beta 2 and 3</em></p><!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Memory leaks by custom delegate]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Working with delegates is a common practice in the coding world of iOS and macOS developers. Many of the core APIs like UITableView have delegates that are called to execute functions so they can get or pass information to another control.</p>
<p>It is easy to use as closures don&apos;</p>]]></description><link>https://somekindofcode.com/memory-leaks-by-custom-delegate/</link><guid isPermaLink="false">5b8f793525f30638fbf0c076</guid><category><![CDATA[Swift]]></category><category><![CDATA[iOS]]></category><category><![CDATA[macOS]]></category><dc:creator><![CDATA[Christopher Beloch]]></dc:creator><pubDate>Thu, 28 Jul 2016 20:56:30 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: markdown--><p>Working with delegates is a common practice in the coding world of iOS and macOS developers. Many of the core APIs like UITableView have delegates that are called to execute functions so they can get or pass information to another control.</p>
<p>It is easy to use as closures don&apos;t always fit the needs.<br>
You can pass the same delegate object to multiple items that will execute the delegate methods. As a delegate is always a protocol, you are safe to use it in code. You have code completion for methods with all the parameters and you know what is available as everything is defined by the protocol.</p>
<p>I use custom delegates from time to time, but I stumbled over some issues recently that caused major memory leaks in my apps.</p>
<p>Take this example:</p>
<pre><code class="language-swift">protocol MyDelegate {
  func someDelegateFunction()
}

class CustomView: UIView {
  var delegate: MyDelegate?
}

class MyViewController: UIViewController, MyDelegate {
  override func viewDidLoad() {
    super.viewDidLoad()
    let newView = CustomView()
    newView.delegate = self
    self.view.addSubview(newView)
  }

  // MyDelegate

  func someDelegateFunction() {
    print(&quot;Do stuff&quot;)
  }
}
</code></pre>
<p>This construct is creating a memory leak.</p>
<h2 id="why">Why?</h2>
<p>Look at ARC. ARC was introduced by Apple in 2011 and automatically deallocates objects from the memory when they are not needed anymore. You don&apos;t have to do this manually. Most apps and frameworks use ARC, because it just works. Well... Most of the time it just works. Not in cases like the one we created at the top.</p>
<p>So what happened? If not specified in any other way, all properties hold a <code>strong</code> reference to their object.<br>
This is OK, if you don&apos;t create a loop of strong references. And that&apos;s what we did.<br>
The ViewController holds the View, which has a delegate that is looping back to the ViewController. If we declare this back reference as weak, everything will work fine and retained memory will be deallocated as soon as we dismiss our ViewController.</p>
<h2 id="solution">Solution</h2>
<p>It is as easy as making the delegate property weak:</p>
<pre><code class="language-swift">class CustomView: UIView {
  weak var delegate: MyDelegate?
}
</code></pre>
<p>But you will get the following error:</p>
<blockquote>
<p>&apos;weak&apos; may only be applied to class and class-bound protocol types, not &apos;MyDelegate&apos;</p>
</blockquote>
<p>The solution is simple, just modify your delegate declaration to make it class-bound:</p>
<pre><code class="language-swift">protocol MyDelegate: class {
  func someDelegateFunction()
}
</code></pre>
<p>Noticed the <code>: class</code> I added? That&apos;s it! Without this addition, even a struct can be used as a delegate, which can&apos;t be hold in a weak reference. A class can and now will.</p>
<h2 id="swiftlinttotherescue">SwiftLint to the rescue</h2>
<p>I use <a href="https://github.com/realm/SwiftLint?ref=somekindofcode.com">SwiftLint</a> in my projects to apply a consistent coding style and be sure everything is documented properly.</p>
<p>The following rules help you prevent this issue: <code>weak_delegate</code> and <code>class_delegate_protocol</code>. These are both enabled by default, so make sure you didn&apos;t opt-out un your <code>.swiftlint.yml</code>.</p>
<p>Below you find an old version of the custom rules I used before SwiftLint implemented similar rules on their own.</p>
<h3 id="myoldcustomrules">My old custom rules</h3>
<p>To prevent this memory leaks from happening again, I added two custom rules to my <code>.swiftlint.yml</code>:</p>
<pre><code class="language-yml">delegate_classprotol:
  name: &quot;class based delegate protocol&quot;
  regex: &quot;protocol[\s]+[\S]+([dD]elegate)[\s]*\{&quot;
  message: &quot;Prevent memory leaks and define delegates as class based protocols so we can create weak references&quot;
  severity: error
  match_kinds: identifier
weak_delegate:
  name: &quot;Prefer weak delegates&quot;
  regex: &quot;^(\s|\t)*(var|let)\s+[\S]*[dD]elegate&quot;
  message: &quot;Prevent memory leaks and refer delegates as weak&quot;
  severity: error
  match_kinds: identifier
</code></pre>
<p>Just add them to the <code>custom_rules</code> block.</p>
<p><strong>Note:</strong> This requires that the protocol identifier ends with <code>delegate</code>. It doesn&apos;t matter if uppercase or lowercase D.<br>
The same rule goes for the property name.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Moving away from CocoaPods]]></title><description><![CDATA[CocoaPods is causing more and more issues with app submissions and takes a lot of your time to fix issues caused by CocoaPods. Change it now!]]></description><link>https://somekindofcode.com/moving-away-from-cocoapods/</link><guid isPermaLink="false">5b8f793525f30638fbf0c075</guid><category><![CDATA[cocoapods]]></category><category><![CDATA[carthage]]></category><dc:creator><![CDATA[Christopher Beloch]]></dc:creator><pubDate>Mon, 27 Jun 2016 12:34:24 GMT</pubDate><media:content url="https://somekindofcode.com/content/images/2019/03/cocoapods-carthage.png" medium="image"/><content:encoded><![CDATA[<img src="https://somekindofcode.com/content/images/2019/03/cocoapods-carthage.png" alt="Moving away from CocoaPods"><p>When you develop native in Apples environment, you stumble over <a href="https://cocoapods.org/?ref=somekindofcode.com">CocoaPods</a> to implement 3rd party libraries in your apps. It adds dependencies that can be installed separately and don&apos;t have to be stored in your respositories.</p><p>I used it for a few years now, but it gets worse every week so I&apos;m leaving and switching to <a href="https://github.com/Carthage/Carthage?ref=somekindofcode.com">Carthage</a>.</p><h2 id="so-what-is-the-problem-with-cocoapods">So what is the problem with CocoaPods?</h2><h3 id="it-s-centralized">It&apos;s centralized</h3><p>All Libraries are submitted to a <a href="https://github.com/CocoaPods/Specs?ref=somekindofcode.com">central git repository</a> hosted on GitHub or you create your own specs repository and modify your <code>Podfile</code> in you project to use that one.</p><h3 id="complicated-syntax">Complicated Syntax</h3><p>The syntax for adding your own private Pods to the dependencies is a little bit messy:</p><pre><code>pod &apos;MySecretLib&apos;, :git =&gt; &apos;git@github.com:SomeKindOfCode/ThatSecretLib.git&apos;
</code></pre><p>And can get worse when you specify a specific branch, commit or version:</p><!--kg-card-begin: markdown--><pre><code class="language-ruby">pod &apos;MySecretLib&apos;, :git =&gt; &apos;git@github.com:SomeKindOfCode/ThatSecretLib.git&apos;, :branch =&gt; &apos;develop&apos;  
pod &apos;MyOtherLib&apos;, :git =&gt; &apos;git@github.com:SomeKindOfCode/MyOtherLib.git&apos;, :tag =&gt; &apos;1.3.5&apos;
</code></pre>
<!--kg-card-end: markdown--><!--kg-card-begin: markdown--><p>Using a version operator like <code>~&gt; 1.0</code> is not possible here.</p>
<!--kg-card-end: markdown--><h3 id="patchwork-without-much-control">Patchwork without (much) control</h3><p>This is one of the main issues for me.</p><!--kg-card-begin: markdown--><p>When you run <code>pod install</code>, CocoaPods will generate a <code>Pods.xcodeproj</code> for you and if it doesn&apos;t exist, creates a Xcode workspace file for you. The last one isn&apos;t an issue, but the first is.</p>
<!--kg-card-end: markdown--><p>When you develop a framework for CocoaPods, you can throw everything into a folder, add a <code>.podspec</code> to your reposoitory and submit it. Everything else is controlled via a 3rd party. There is no requirement to create a custom Xcode project.</p><p>Due to these steps which change a few things with each CocoaPods Version I recently ran into a large amount of signing issues.<br>It cost me a day of work to get my app fixed to be submitted to the App Store. The only fix was another project manipulation I had to add to my <code>Podfile</code>.</p><!--kg-card-begin: markdown--><pre><code class="language-ruby">post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings[&apos;EXPANDED_CODE_SIGN_IDENTITY&apos;] = &quot;&quot;
            config.build_settings[&apos;CODE_SIGNING_REQUIRED&apos;] = &quot;NO&quot;
            config.build_settings[&apos;CODE_SIGNING_ALLOWED&apos;] = &quot;NO&quot;
        end
    end
end
</code></pre>
<!--kg-card-end: markdown--><p>This disabled the codesigning on the frameworks. I hate this step and this has to be done for each app you develop.<br>I got sick of it. Every new version broke something different so I moved over to <a href="https://github.com/Carthage/Carthage?ref=somekindofcode.com">Carthage</a> which gives you much more control, is decentralized and builds real frameworks!</p><p>This automatic generation is also the problem why you can&apos;t migrate all Pods to Carthage. Most will work, but every now and then I&apos;ve stumbled over projects that were created in the most simple way. If you want to develop your own Framework, consider using something like <a href="https://github.com/JohnSundell/SwiftPlate?ref=somekindofcode.com">SwiftPlate by John Sundell</a>.</p><!--kg-card-begin: markdown--><p><em><p style="text-alignment: center; margin: 0px;">Updated March 1st 2019</p></em></p>
<!--kg-card-end: markdown-->]]></content:encoded></item></channel></rss>