Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 4 update #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
4.0
2 changes: 1 addition & 1 deletion NibDesignable.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'NibDesignable'
s.version = '3.0.0'
s.version = '4.0.0'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'Elegant way of enabling IBDesignable on your nib-based views'
s.homepage = 'https://github.com/mbogh/NibDesignable'
Expand Down
81 changes: 44 additions & 37 deletions NibDesignable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,42 @@ public protocol NibDesignableProtocol: NSObjectProtocol {
/**
Identifies the view that will be the superview of the contents loaded from
the Nib. Referenced in setupNib().

- returns: Superview for Nib contents.
*/
var nibContainerView: UIView { get }
// MARK: - Nib loading

/**
Called to load the nib in setupNib().

- returns: UIView instance loaded from a nib file.
*/
func loadNib() -> UIView
/**
Called in the default implementation of loadNib(). Default is class name.

- returns: Name of a single view nib file.
*/
func nibName() -> String
}

extension NibDesignableProtocol {
// MARK: - Nib loading

/**
Called to load the nib in setupNib().

- returns: UIView instance loaded from a nib file.
*/
public func loadNib() -> UIView {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: self.nibName(), bundle: bundle)
return nib.instantiate(withOwner: self, options: nil)[0] as! UIView // swiftlint:disable:this force_cast
}

// MARK: - Nib loading

/**
Called in init(frame:) and init(aDecoder:) to load the nib and add it as a subview.
*/
Expand All @@ -77,12 +77,9 @@ extension NibDesignableProtocol {
}

extension UIView {
public var nibContainerView: UIView {
return self
}
/**
Called in the default implementation of loadNib(). Default is class name.

- returns: Name of a single view nib file.
*/
open func nibName() -> String {
Expand All @@ -92,13 +89,16 @@ extension UIView {

@IBDesignable
open class NibDesignable: UIView, NibDesignableProtocol {
public var nibContainerView: UIView {
return self
}

// MARK: - Initializer
override public init(frame: CGRect) {
super.init(frame: frame)
self.setupNib()
}

// MARK: - NSCoding
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand All @@ -108,16 +108,16 @@ open class NibDesignable: UIView, NibDesignableProtocol {

@IBDesignable
open class NibDesignableTableViewCell: UITableViewCell, NibDesignableProtocol {
public override var nibContainerView: UIView {
public var nibContainerView: UIView {
return self.contentView
}

// MARK: - Initializer
override public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.setupNib()
}

// MARK: - NSCoding
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand All @@ -127,33 +127,36 @@ open class NibDesignableTableViewCell: UITableViewCell, NibDesignableProtocol {

@IBDesignable
open class NibDesignableTableViewHeaderFooterView: UITableViewHeaderFooterView, NibDesignableProtocol {

public override var nibContainerView: UIView {
return self.contentView
}

// MARK: - Initializer
override public init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
self.setupNib()
}

// MARK: - NSCoding
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupNib()
}
public var nibContainerView: UIView {
return self.contentView
}
// MARK: - Initializer
override public init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
self.setupNib()
}
// MARK: - NSCoding
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupNib()
}
}

@IBDesignable
open class NibDesignableControl: UIControl, NibDesignableProtocol {
public var nibContainerView: UIView {
return self
}

// MARK: - Initializer
override public init(frame: CGRect) {
super.init(frame: frame)
self.setupNib()
}

// MARK: - NSCoding
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand All @@ -163,13 +166,16 @@ open class NibDesignableControl: UIControl, NibDesignableProtocol {

@IBDesignable
open class NibDesignableCollectionReusableView: UICollectionReusableView, NibDesignableProtocol {
public var nibContainerView: UIView {
return self
}

// MARK: - Initializer
override public init(frame: CGRect) {
super.init(frame: frame)
self.setupNib()
}

// MARK: - NSCoding
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand All @@ -179,19 +185,20 @@ open class NibDesignableCollectionReusableView: UICollectionReusableView, NibDes

@IBDesignable
open class NibDesignableCollectionViewCell: UICollectionViewCell, NibDesignableProtocol {
public override var nibContainerView: UIView {
public var nibContainerView: UIView {
return self.contentView
}

// MARK: - Initializer
override public init(frame: CGRect) {
super.init(frame: frame)
self.setupNib()
}

// MARK: - NSCoding
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupNib()
}
}