Utils for iOS development.
Initialize views/controllers from code/xib/storyboard with one simple interface .initiate()
Controllers example:
// Controller without nib.
class FooController: UIViewController, CodeInitable { }
let foo = FooController.initiate()
// Controller with xib named "FooContoller"
class BarController: UIVewController: XibInitable {
static var xibName: String { "FooContoller" }
}
let bar = BarController.initiate()
// Controller with storyboard named "BazStoryboard" with id "BazControllerId"
class BazController: UIVewController: StoryboardInitable {
static var storyboardId: String { "BazControllerId" }
static var storyboardName: String { "BazStoryboard" }
}
let baz = BazController.initiate()
Reading custom object/JSON/Data from Bundle.
Bundle contains foo.json
file.
{
"bar": 100
}
Reading:
struct Foo {
let bar: Int
}
let foo: Foo = BundleFileReader.readObject("foo")
More about BundleFileReader in action here.
Lightweight tool for managing local notifications. Tools:
- Use
requestAuthorization
to request User's approve for sending notifications - Use
getAuthorizationStatus
to check current authorization status - Use
willPresent
to ask the delegate what to do after receiving notification - Use
didRecieve
to inform delegate about receiving notification
Example:
LocalNotificationService.shared.getAuthorizationStatus { status in
if status == .authorized {
// Do some...
} else {
// Do another...
}
}
LocalNotificationService examle
Useful extensions for all code situations
let number = Float.two // 2.0
let closure = Closure.Int // (Int) -> Void
let color = UIColor(hex: "#FFFFFF") // White Color
// and others
MulticastDelegate hepls to manage more than one delegate.
protocol FooDelegate: AnyObject {
func bar()
}
let multicastDelegate = MulticastDelegate<FooDelegate>()
multicastDelegate.add(delegate: object)
multicastDelegate.remove(delegate: object)
multicastDelegate.invokeForEachDelegate { delegate in
delegate.bar()
}
Live preview for UIKit views/controllers.
class FooView: UIView { ... }
struct FooView_Previews: PreviewProvider {
static var previews: some View {
ViewPreview {
FooView()
}
}
}
Base button class with a lots of customization.
Usage from code:
class FooButton: Button { }
Usage from nib:
- Set your button class to
Button
in IB - Set Type = Custom in IB
- Set Style = Default in IB
Simple view layout
let superview = UIView()
let subview = UIView()
superview.layoutSubview(subview, with: LayoutInsets.zero, safe: true)
StackView with item content builder.
let items = (0..<10).map { Int($0) }
let stackView = ItemsStackView<Int, UILabel>(
axis: .horizontal,
distribution: .fill,
alignment: .fill,
spacing: 10,
edgeInsets: .zero,
items: items
) { item in
let label = UILabel()
label.text = "\(item)"
return label
}
- Swift 5.0 +
- iOS 13.0 +
- Make
pod init
- Add the following to Podfile
pod 'Utils', :git => 'https://github.com/MobileUpLLC/Utils', :tag => '0.1.0', :branch => 'develop'
- Make
pod install
Download and drag files from Source folder into your Xcode project.
Swift Package Manager
dependencies: [
.package(url: "https://github.com/MobileUpLLC/Utils", .upToNextMajor(from: "0.1.0"))
]
Utils is distributed under the MIT License.