diff --git a/GliaWidgets/Resources/FontProvider.swift b/GliaWidgets/Resources/FontProvider.swift index 24519605c..9f0b9d90c 100644 --- a/GliaWidgets/Resources/FontProvider.swift +++ b/GliaWidgets/Resources/FontProvider.swift @@ -16,30 +16,35 @@ internal class FontProvider { } func font(named: String, size: CGFloat) -> UIFont { - // swiftlint:disable force_unwrapping - return UIFont(name: named, size: size)! + return UIFont(name: named, size: size) ?? .systemFont(ofSize: size) } private func loadFonts() { - fonts.forEach { loadFont(named: $0) } + _ = fonts.first(where: { !loadFont(named: $0) }) } - private func loadFont(named name: String) { + private func loadFont(named name: String) -> Bool { let bundle = Bundle(for: BundleToken.self) - guard let pathForResourceString = bundle.path(forResource: name, ofType: "ttf"), + guard + let pathForResourceString = bundle.path(forResource: name, ofType: "ttf"), let fontData = NSData(contentsOfFile: pathForResourceString), let dataProvider = CGDataProvider(data: fontData), - let fontRef = CGFont(dataProvider) else { - fatalError("Could not load fonts. Perhaps they are not inculded in the bundle?") + let fontRef = CGFont(dataProvider) + else { + print("Could not load font='\(name)'. Perhaps they are not inculded in the bundle?") + return false } var errorRef: Unmanaged? let registrationResult = CTFontManagerRegisterGraphicsFont(fontRef, &errorRef) if !registrationResult { - fatalError("Could not load fonts") + print("Font='\(name)' has not been registered properly. Error='\(errorRef.debugDescription)'.") + return false } + + return true } } diff --git a/README.md b/README.md index 6a410a1c5..e56615113 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,22 @@ pod install xed GliaWidgets.xcworkspace ``` +## Cocoapods + +For integration, the `GliaWidgets` into your project via [CocoaPods](https://cocoapods.org/) modify your `Podfile` +``` +# Podfile + +source 'https://github.com/CocoaPods/Specs.git' +source 'https://github.com/salemove/glia-ios-podspecs.git' + +user_frameworks! + +target 'YOUR_TARGET_NAME' do + pod 'GliaWidgets', git: 'https://github.com/salemove/ios-sdk-widgets', tag: 'SDK_VERSION' +end + +``` ## Communication