• Skip to main content
  • Skip to footer

InRhythm

Your partners in accelerated digital transformation

  • Who We Are
  • Our Work
  • Practices & Products
  • Learning & Growth
  • Culture & Careers
  • Blog
  • Contact Us

SwiftUI

Dec 20 2022

A Comprehensive Introduction To Swift Package Manager

Introduction

The Swift Package Manager (SwiftPM) is Apple’s tool for managing package dependencies for Swift application development. SwiftPM has been an integrated part of Swift since v3.0.

So, what are Packages? Packages contain reusable code or other resources stored in repositories that your application needs to provide a feature or function. Some examples include, but are not limited to, the fonts and color scheme for your app, a library that provides access to a web resource, a file with images required by your application. Other examples are the APIs and Frameworks that add functionality to your app and simplify your coding tasks.

Let’s work together and breakdown a high-level overview of basic SwiftPM usage and its associated features.

What Do Package Managers Bring To The Table?

Package Managers give developers a way to control which packages and which versions of those packages that the project will consume.

Other features include:

  • Allows easy use of light-weight, reusable libraries
  • Reduces code duplication
  • Supports development best practices by simplifying and supporting modular coding (easy module/package creation)

While it is possible to manually manage dependencies in a project, it isn’t practical for anything but the smallest of applications. Best practices fall on the side of using a package manager to handle this function automatically.

SwiftPM supports Swift 3+ and XCode 8+. Since Swift 5 and Xcode 11, SwiftPM has had cross-platform support for iOS, macOS, and tvOS.

Are There SwiftPM Alternatives?

There are two mainstream alternatives, CocoaPods and Carthage. Both are third-party tools requiring installation and much configuration before use.

CocoaPods

No alt text provided for this image

CocoaPods (2011) – Supports Swift 5+ and Xcode 3.11+ – Mature and stable. A centralized, easy-to-use command-line tool for package dependency management and integration into the application. CocoaPods is written in Ruby.

However, Cocoapods lacks direct control over project configuration and is basically a blackbox. CocoaPods also experiences random build failures that can’t be explained. Resolving these often involves removing and reinstalling CocoaPod dependencies from the project, clearing caches, and completely rebuilding the entire project. These steps can add a significant amount of time to the development process, especially on large projects.

Each CocoaPod dependency must have a “Podspec” file to define the metadata for that dependency. These files are typically uploaded to a different repository from the dependency itself. A “Podfile” within the app project will include a reference to this repository, and CocoaPods will use the information in this Podfile to fetch and install all of the dependencies for the app project. 

Carthage

No alt text provided for this image

Carthage (2014) – A decentralized command-line tool for dependency management. Developers have full project control and must manually provide all package and dependency information. Carthage pulls the packages the developer specifies.Configuration requires much more manual work than CocoaPods and is somewhat complicated.

Using SwiftPM

SwiftPM has many advantages over Carthage and CocoaPods. Foremost, SwiftPM is a native Apple tool integrated into Swift. Other advantages include a quick and simple configuration, easier control over packages and their sub-dependencies, and a GUI built into Xcode for managing package configurations. Each package’s metadata is defined in a “Package.swift” file, which  resides in the same repository as the package source files. 

Package Resolution

With the Package dependencies configured in the SwiftPM GUI, Xcode will download the packages and resolve dependencies at build time with no further developer interaction.

When setting dependencies, you have the following options:

  • By Version: Next Version, Up to next minor, Range, or a specific commit
  • Branch (Specify)
  • Commit(Specify)

Adding A Package To Your Project

  1. Swift Packages> Add Package Dependency 
  2. On the “Choose Package Repository” dialog, enter the desired Repository.
  3. Click Next. 
  4. On the “Choose Package Options” dialog, set the dependency rules (Versions, Branches, Commits). 
  5. Click Next. Xcode now fetches the dependency.
  6. On the “Add Package to YourPrjName dialog,” ensure that the relevant packages are checked and the proper Target is selected in the Add to Target cell.
  7. Click Finish.

Your package now appears in the Navigator under Swift Package Dependencies. Note that SwiftPM can reference both local and remote packages.

Create A Module And Add A Local Package With SwiftPM

SwiftPM simplifies the process of modularizing your code and adding it as a package to a local or external repository. This section will briefly describe the process of creating a module and adding it to a local repository.

  1. Identify a self-contained portion of code or another resource that is suitable for use in a module.
  2. Create a new file: Files > New Package. Name the package accordingly and add it to your application using the same dialog.
  3. Copy the code or resource to the new file.
  4. Delete the existing code or resource from the app
  5. Add the new package to the Application Target. In “Application Project Settings,” add the new package under Frameworks and Libraries.
  6. In the Package code, define the platforms and versions where this Package works.
  7. In the Application’s code files, import the new package into every file where its code or where its resources are used. 

If desired, you could upload the new Package to an external repository for use by developers outside your organization.

Additionally, SwiftPM will allow you to create and use binary packages. Binary packages permit developers to distribute libraries and frameworks without also distributing their source code.

Package Distribution

You can use SwiftPM to distribute resources, in addition to frameworks and libraries. SwiftPM also has built-in support for Apple’s  DocC Documentation format, which makes it easy to build robust interactive documentation files and tutorials. 

The Future

SwiftPM is a mature product still under active development to improve and add new features. Usage stats currently show it being about equal in popularity with CocoaPods. However, since SwiftPM is a native tool that requires no additional work to begin using, its future is more sure than that of CocoaPods or Carthage.

Happy coding!

To learn more about Swift Package Manager as well as its influence in mobile development and to experience Andrew Balmer’s full Lightning Talk session, watch here.

Written by Kaela Coppinger · Categorized: Code Lounge, InRhythmU, Learning and Development, Software Engineering · Tagged: best practices, INRHYTHMU, ios, iOS Ecosystem, learning and growth, Package Management, software engineering, SwiftPM, SwiftUI

Nov 01 2022

An Introduction To SwiftUI Animations

Overview

Since the very beginning of iOS, animations have been a key part of the user experience. Animation is a brilliant way to wow users, and make an app look and feel unique. Practically speaking, animation can grab a user’s attention, and allow them to focus on what’s most important. It can help users intuitively understand how to navigate an app or alert them to important changes.

SwiftUI takes care of all the complexity in making effects by automatically animating any transitions that may happen. Done are the days of writing complicated code for a singular animated transition – the framework comes with enough built-in effects that can perform different animations.

In Joshua Buchanan’s Lightning Talk session, we will breaking down the following topics:

  • Overview
  • Why Have Animations?
  • SwiftUI Animation Options
  • How To Add Animations With SwiftUI
  • Live Demonstration
  • Closing Thoughts

Why Have Animations?

Animations are an easy way to show users the functionality hidden behind a beautiful wrapper.

Animations are quite an important part of any application because it draws users’ attention. An animation is simply a collection of images that are repeated at high speed, but animations can set your application apart.

Mobile app animations occupy an important place in the design of the whole user experience of an app. They are great for communicating a message and creating a feeling by not limiting the method with static images or texts. The dynamism that in-app animations inherently have makes the user journey more vivid and delightful. Thanks to that, an animated app can achieve higher user engagement rates.

SwiftUI Animation Options

Animations on SwiftUI have a variety of options built into its starting interface. These options allow for a number of different transitions to take place swiftly and automatically. 

There are a number of varying involvement regarding these options, from basic to advanced – each piece brings a unique visual perspective to life.

The primary basic animation options available to a mobile developer utilizing SwiftUI for their mobile application are:

  • Enable
  • Offset
  • Color
  • Scale

The most popular of these advanced options being:

Repeat Count / Reverse

Duration Options (Speed)

Curve Options

How To Add Animations With SwiftUI

SwiftUI has built-in support for animations with its animation() modifier. To use this modifier, place it after any other modifiers for your views, tell it what kind of animation you want, and also make sure you attach it to a particular value so the animation triggers only when that specific value changes.

SwiftUI animates the effects that many built-in view modifiers produce, like those that set a scale or opacity value. You can animate other values by making your custom views conform to the Animatable protocol, and telling SwiftUI about the value you want to animate.

When an animated state change results in adding or removing a view to or from the view hierarchy, you can tell SwiftUI how to transition the view into or out of place using built-in transitions that AnyTransition defines, like slide or scale. You can also create custom transitions.

Live Demonstration

Joshua Buchanan has crafted an intuitive test to demonstrate real time code and their animated results via SwiftUI:

Be sure to follow Joshua’s entire Lightning Talk to follow along with these steps in real time.

Closing Thoughts

In SwiftUI, Animation is nothing but the change of the state from start to finish with different curves and velocities. The syntax is mostly easy to understand and quick to implement. Animating is quite easy with the use of different implicit animation like easeIn, easeOut, linear, spring, and interpolating spring. A developer can create awesome animations with just a few lines of code in SwiftUI.

Happy coding!

To learn more about the implementation of SwiftUI Animations and to experience Joshua Buchanan’s full Lightning Talk session, watch here. 

Written by Kaela Coppinger · Categorized: Code Lounge, Design UX/UI, DevOps, Learning and Development, Product Development · Tagged: coding, INRHYTHMU, Mobile Development, software development, SwiftUI, ux

Aug 01 2022

The Accelerating Future Of Server-Side Swift In Vapor

Overview

Server-Side Swift is an amazing new opportunity for coders to build fast, safe, and scalable back-end applications. This new open-source framework has enabled developers to use the Swift language on major servers, so nothing can stand between you and effectively creating your backend. 

In Austin-Michael Komatz’s Lightning Talk session, we will be uncovering the following topics:

  • What Is Swift?
  • Introducing Vapor
  • Test Your Skills
  • Closing Thoughts

What is Swift? 

In the simplest of terms, Swift functions as a general-purpose programming language – meaning, it can be used in any environment for a variety of applications.

Swift has a number of unique features that make it a versatile language to have in your personal “programmer’s tool box”:

  • As open source software (OSS), Swift is a coding language that can be seen, modified, and distributed by anyone
  • At its core, Swift is written in C++. C++ is an object-oriented programming (OOP) language that is one of the best sources for creating large-scale applications

The primary win associated with Swift, is that it’s not a language for only making iOS apps – but instead it can be applied seamlessly to a number of applications – making it an immeasurable advantage to implement into your industry practice.

Introducing Vapor 

Vapor is more than just a web framework. The project includes over a hundred official and community maintained server-first Swift packages. Vapor is a framework for writing HTTP server applications, front end websites, backends, and APIs in Swift.

Vapor has a unique set of properties that set it apart from other frameworks:

  • It is 100% written in Swift
  • It is a non-blocking, event-driven architecture built on top of Apple’s SwiftNIO
  • With a protocol orientation, it allows Vapor to be scalable, modular, and a type-safe network

Vapor allows you to create complex, full-featured applications that can power mobile applications or stand on their own.

Example: The below Vapor code base represents the unique “package manager” the platform utilizes in order to easily implement code cross-functionally. 

Vapor offers many features, some of the most important and widely used ones include:

Databases

Databases allow data to be persisted and stored for later. This data can then be read back at any time. Vapor provides an ORM for working easily with a variety of databases. This allows developers to easily access their database without having to write custom queries.


Vapor allows you to easily create and manage RDS and Aurora Serverless databases directly from the Vapor UI or while using the Vapor CLI. Database backups are automatically performed and you may restore a database to any point in time (down to the second) within the backup retention window.

Vapor supports a number of commonly used databases, including (but not limited to):

  • PostgreSQL
  • redis 
  • SQLite
  • MySQL
  • mongoDB

HTTP

Vapor’s client API allows you to make HTTP calls to external resources. It is built on async-http-client and integrates with the content API.

Vapor supports HTTP/1, HTTP/2, and protocol upgrades like WebSockets. The server also supports Transport Layer Security (TLS).

Authentication

Authentication is the process of transforming a unique token (identifier) to actual user data. This can be a cookie with a session identifier stored in a browser, or in this case a JWT (JSON Web Token), but based on this ID the backend can retrieve the associated user object.

The end user signs in using a login form on a website (or an API endpoint), and sends the usual credentials (email, password) to the backend. If those credentials were valid, then the server will return a (randomly generated) identifier to the client. 

Websockets

WebSockets allow for two-way communication between a client and server. Unlike HTTP, which has a request and response pattern, WebSocket peers can send an arbitrary number of messages in either direction. Vapor’s WebSocket API allows you to create both clients and servers that handle messages asynchronously.

Testing Your Skills

You’ve unpacked quite a few primary principles of the Server-Side Swift backend approach… But the best way to learn is through practical and tangible demonstration.

Austin-Michael Komatz has crafted an intuitive demonstration to help guide you through these principles in practicum: 

Using a coded chat application, Vapor is able to connect the two threads via a websocket to allow for real-time communications. 

Closing Thoughts

Why do you want to use Vapor as a backend engineer? The simple answer is– it uses Swift! It’s an ultra-modern language that is leading architecture use cases in the industry right now.

The longer answer… the abundance of functional benefits put it ahead of the industry curve in terms of speed, stability, and passionate community interactions.

Vapor is an optimistic look to the future for backend engineers, ensuring and maintaining a bigger and better future!

Happy coding!

To learn more about the introduction of Server-Side Swift in Vapor and to experience Austin-Michael Komatz’s full Lightning Talk session, watch here. 

Written by Kaela Coppinger · Categorized: Code Lounge, InRhythmU, Product Development, Web Engineering · Tagged: best practices, INRHYTHMU, learning and growth, SwiftUI, Vapor

Footer

Interested in learning more?
Connect with Us
InRhythm

110 William St
Suite 2601
New York, NY 10038

1 800 683 7813
get@inrhythm.com

Copyright © 2023 · InRhythm on Genesis Framework · WordPress · Log in

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT