Topics covered
Requirements
Beagle Scaffold is a supporting framework that has a default implementation of the network layer and logger, all embedded in BeagleDefaults, so you can start using Beagle faster.
Step 1: Create a new app project using Xcode.
Step 2: On your Terminal, run pod init
to create a Podfile and add Beagle Scaffold as a dependency to your project, like this:
target 'MyApp' do
pod 'BeagleScaffold'
end
If you’re not familiar with CocoaPods, check out their documentation.
Step 3: Run pod install
to install Beagle Scaffold in your app. This command will generate a Workspace that you will use from now on.
To start configuring Beagle in your app, follow the steps:
Step 1: You need to go into the file SceneDelegate, import the lib BeagleScaffold
and call the function named start()
from Beagle Scaffold’s class BeagleConfig
, inside method scene()
:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
BeagleConfig.start()
guard let _ = (scene as? UIWindowScene) else { return }
}
Step 2: You need to initialize the project using a View Code approach:
scene
, name the constant guard let
created by Xcode to windowScene
:guard let windowScene = (scene as? UIWindowScene) else { return }
window
created outside the function scope, using windowScene
:window = UIWindow(windowScene: windowScene)
window?.rootViewController
become BeagleScaffoldDemoViewController
and call the method makeKeyAndVisible()
. Your code should be like this:func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
BeagleConfig.start()
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.rootViewController = BeagleScaffoldDemoViewController
window?.makeKeyAndVisible()
}
Step 3: Run your project, and you should see a sample screen with all Beagle components on the simulator.
In this section, you will learn how to customize your Beagle Scaffold. Let’s start with the most basic one: change the base Url. This will happen when you try rendering your first server-driven screen, which will be right after displaying the demo screen.
Step 1: Create a new file, called BeagleConfigurations.swift
.
setup
;setup
function, instantiate a variable called dependencies
that is a BeagleDependencies
;urlBuilder
to match the base URL. In this example, it will be a localhost url, such as http://localhost:8080
;dependencies
variable as a parameter to the start
method from BeagleScaffold’s BeagleConfig
.Your BeagleConfigurations
class should be like this:
import Foundation
import Beagle
import BeagleScaffold
struct BeagleConfigurations {
static func setup() {
let dependencies = BeagleDependencies()
dependencies.urlBuilder = UrlBuilder(baseUrl: URL(string: "http://localhost:8080"))
BeagleConfig.start(dependencies: dependencies)
}
}
Step 2: Now we need to change the SceneDelegate
class. Inside the method scene
, you’ll no longer call BeagleConfig.start()
. Call BeagleConfigurations.setup()
instead. You can see your screen by giving an endpoint to a BeagleScreenViewController
, but you need to import Beagle first. Then you can use this controller as your new window?.rootViewController
like this:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
BeagleConfigurations.setup()
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.rootViewController = BeagleScreenViewController(.remote(.init(url: "/yourEndpoint")))
}
Step 3: Since your endpoint won’t be a secure connection, you will need to allow an arbitrary load in your info.plist
file.
To do this, follow the steps:
App Transport Security Settings
by clicking on the +
icon at the Information Property List
level;App Transport Security Settings
level, click on the >
icon to open it up;Allow Arbitrary Loads
and set it to YES
.Beagle Scaffold is a lib that supports newcomers to use Beagle, it helps you render a screen as fast as possible, for example. And you can also customize Beagle Scaffold to match your needs.
You can easily change the endpoint to render a new screen instead of Beagle Scaffold’s demo, and you are able to customize every Beagle property inside Beagle’s dependencies.
There is a set of properties that you should customize, such as the NetworkClient and Logger. If your app is going to be delivered to production, it’s essential to configure your security levels and what information you want to log.
You can create these layers using these tutorials:
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.