/YFUtils

iOS common utilities in Swift

Primary LanguageSwiftMIT LicenseMIT

YFUtils

Author

yfben, benxyz.chen@gmail.com

Installation

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate YFUtils into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '9.0'

target '<Your Target Name>' do
    use_frameworks!
    pod 'YFUtils'
end

Then, run the following command:

$ pod install

Usage

Internationalization

  1. Add Localizable.strings file and localize it with preferred language
  2. Subclass LocalizedViewController class
  3. Override setupLocalizedText() in the subclass
    override func setupLocalizedText() {
      // to localize "Localized title" string, append `.localized()` to it
      self.title = "Localized title".localized()
    }

Display message and error

alert(message: "message_button_message".localized(), type: .error)

Display loading view

// display localized string for "loading_view_title" for at least 2 seconds
LoadingView.show(message: "loading_view_title".localized(), duration: .milliseconds(Int(2.0 * 1000)))
LoadingView.hide()

Reuse XIB in Strorybaord

  1. Design your reusable xib and create the corresponding swift file
  2. In the swift file
    • Subclass CustomView and mark it with @IBDesignable annotation
    • Mark designable property with @IBInspectable
    • Override setupCustomNib()
  3. In the storyboard file, set the Custom Class as the corresponding class
  4. In the xib file, set the Custom Class of File's Owner as the corresponding class
  5. Enjoy it!!!