A base for iOS Applications made with ❀️ by Mindera 🀠
Branch: master
Clone or download
p4checo Make `NetworkResource` request creation async πŸ“¬ (#179)
Until now, `Resource` fetch authentication was made via a single
`NetworkAuthenticator` injected on a `URLSessionNetworkStack`, which
was used to enrich the requests of the Resources being scheduled on the
stack. This had some limitations:

1. Either all `Resource` fetches were authenticated, or none (depending
on whether `authenticator` was set or not on the stack).

2. Since the `authenticator` was shared when set, supporting different
authentication schemes (e.g. different API's) or unauthenticated
fetches on the same stack required creating a complex
`NetworkAuthenticator` (containing / proxying all logic), which was
obviously not ideal.

To solve the above problems and give more flexibility to our stack, the
`NetworkResource` keeps being responsible for creating its requests,
with the difference that now it does so *asynchronously*. This allows
each `NetworkResource` implementation to create (and enrich) its
requests, only passing them to the stack when they are ready to be
scheduled. As such, more complex request building logic like
authentication can now be done by the Resource itself (which can have
its own `RequestAuthenticator` instance, for example).

## Changes

- Renamed `NetworkAuthenticator` to `RequestAuthenticator` and
`RetryableNetworkAuthenticator` to `RetryableRequestAuthenticator`,
and refined to contain associated types.

- Created specialized `URLRequestAuthenticator` and
`RetryableURLRequestAuthenticator` that work with `URLRequest`, `Data`
and `URLResponse`.

- Updated `NetworkResource` to have a `Request` associated type, and a
new asynchronous `makeRequest()` API.

- Removed `RelativeNetworkResource` and `StaticNetworkResource`.

- Created `HTTPResourceEndpoint` to represent an HTTP endpoint, and
contain default `URLRequest` building logic.

- Created `HTTPNetworkResource` to represent a Resource with a
`HTTPResourceEndpoint`, and contain a default `makeRequest()`
implementation.

- Created `AuthenticatedHTTPNetworkResource` that extends
`HTTPNetworkResource` and has a `NetworkAuthenticator` instance, and
contain a default `makeRequest()` implementation.

- Added UT's for the new types.

- Adjusted existing UT's.

- Cleaned up and unified some `MockResource`s in UT's.

- Added some documentation on the new stuff.
Latest commit fe77ade Feb 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Alicerce.playground Add SwiftLint to the project (#133) Nov 20, 2018
Alicerce.xcodeproj Make `NetworkResource` request creation async πŸ“¬ (#179) Feb 11, 2019
Alicerce.xcworkspace Use Result in the network layer. (#146) Jun 28, 2018
Carthage/Checkouts Bump Result to 4.1.0 (#180) Feb 11, 2019
Documentation Use Result in the network layer. (#146) Jun 28, 2018
Resources Improve Cancelable and Network cancellation ❌ (#171) Oct 17, 2018
Sources Make `NetworkResource` request creation async πŸ“¬ (#179) Feb 11, 2019
Tests
.codecov.yml Fix ignore on codecov.yml and specify packages on travis.yml (#25) Apr 16, 2017
.gitignore Project setup Dec 16, 2016
.gitmodules Bump Result to 4.1.0 (#180) Feb 11, 2019
.swiftlint.yml Add SwiftLint to the project (#133) Nov 20, 2018
.travis.yml Use travis homebrew addon for reliability (#178) Dec 18, 2018
Alicerce.podspec Bump version to 0.4.0 Nov 7, 2018
Brewfile
CONTRIBUTING.md Add CONTRIBUTING.md (#107) Feb 23, 2018
Cartfile Bump Result to 4.1.0 (#180) Feb 11, 2019
Cartfile.resolved Bump Result to 4.1.0 (#180) Feb 11, 2019
LICENSE Add antitypical/Result as a dependency. (#144) Jun 25, 2018
Package.swift Add antitypical/Result as a dependency. (#144) Jun 25, 2018
README.md Bump version to 0.4.0 Nov 7, 2018

README.md

Alicerce πŸ—

from Portuguese:

noun β€’ [ masculine ] /ali’sΙ›ΙΎsΙͺ/

groundwork, foundation, basis

license release platforms Swift 4.2 Carthage CocoaPods SwiftPM Build Status codecov

What is it? πŸ€”

Ever felt that you keep repeating yourself every time you start a new project? That you would like to have all those useful utils and helpers you love already available? We felt that way too! Thus, Alicerce was born. πŸ—

Alicerce is a framework that aims to serve as a starting point for iOS applications, by providing the foundations for many of the common functionalities a modern application requires, as well as be a repository for those small utils and helpers that make our life easier.

It is designed with an MVVM architecture in mind, but you'll find most components are architecture agnostic.

Main features ✨

  1. Analytics πŸ”
  2. Deep Linking πŸ”—
  3. Logging πŸ“
  4. Network 🌍
  5. Persistence πŸ’Ύ
  6. Performance Metrics πŸ“ˆ
  7. Utils βš™οΈ
  8. UI πŸ“²

Documentation πŸ“„

All the documentation can be found in the Documentation folder:

  1. Network
  2. more coming soon...

Examples πŸ‘€

TODO

Installation πŸ”§

Alicerce supports iOS 9.0+ and requires Xcode 10+.

For Xcode 9.3 (Swift 4.0) compatibility, Alicerce 0.3.0 should be used.

CocoaPods

If you use CocoaPods to manage your dependencies, simply add Alicerce to your Podfile:

pod 'Alicerce', '~> 0.4'

Carthage

If you use Carthage to manage your dependencies, simply add Alicerce to your Cartfile:

github "Mindera/Alicerce" ~> 0.4

If you use Carthage to build your dependencies, make sure you have added Alicerce.framework to the "Linked Frameworks and Libraries" section of your target, and have included them in your Carthage framework copying build phase.

Swift Package Manager

If you use Swift Package Manager, simply add Alicerce as a dependency of your package in Package.swift:

.Package(url: "https://github.com/Mindera/Alicerce.git", majorVersion: 0, minor: 4),

git Submodule

  1. Add this repository as a submodule.
  2. Drag Alicerce.xcodeproj into your project or workspace.
  3. Link your target against Alicerce.framework.
  4. If linking against an Application target, ensure the framework gets copied into the bundle. If linking against a Framework target, the application linking to it should also include Alicerce.

Setup

Setting up the project for development is simple:

  1. Clone the repository.
  2. Retrieve the project dependencies using one of the following commands from the project root directory:
    • if you have Carthage installed: carthage checkout
    • or: git submodule update --init --recursive
  3. Open Alicerce.xcworkspace
  4. Build Result-iOS scheme
  5. Build Alicerce scheme

Contributing πŸ™Œ

See CONTRIBUTING.

License

Alicerce is Copyright (c) 2016 - 2018 Mindera and is available under the MIT License. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

With ❀️ from Mindera πŸ€“