Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #24 from 4alltecnologia/bugfix/fix_nib_instantiable
Browse files Browse the repository at this point in the history
Fix and test NibInstantiatable type
  • Loading branch information
betinafarias authored Aug 27, 2019
2 parents fddf820 + c2d37ec commit 07b5976
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
4 changes: 4 additions & 0 deletions UtilitiesCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
C99B09B722B27CC800AADF3B /* Decode+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99B09B622B27CC800AADF3B /* Decode+Extension.swift */; };
C9ED4A5B229D91F100939BFB /* Encodable+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ED4A5A229D91F100939BFB /* Encodable+Extension.swift */; };
C9ED4A5D229D920800939BFB /* EncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ED4A5C229D920800939BFB /* EncodableTests.swift */; };
D582E6E22314802200FC8E6D /* TestNib.xib in Resources */ = {isa = PBXBuildFile; fileRef = D582E6E12314802200FC8E6D /* TestNib.xib */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -135,6 +136,7 @@
C99B09B622B27CC800AADF3B /* Decode+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Decode+Extension.swift"; sourceTree = "<group>"; };
C9ED4A5A229D91F100939BFB /* Encodable+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Encodable+Extension.swift"; sourceTree = "<group>"; };
C9ED4A5C229D920800939BFB /* EncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncodableTests.swift; sourceTree = "<group>"; };
D582E6E12314802200FC8E6D /* TestNib.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TestNib.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -248,6 +250,7 @@
C9835D0322833FBD00DB672B /* UITextFieldTests.swift */,
0279FD57230C14EA00AFD2CB /* UIViewTests.swift */,
0279FD5B230C177400AFD2CB /* UIViewControllerTests.swift */,
D582E6E12314802200FC8E6D /* TestNib.xib */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -385,6 +388,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D582E6E22314802200FC8E6D /* TestNib.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
9 changes: 2 additions & 7 deletions UtilitiesCore/Extensions/UIView+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
// Copyright © 2019 4all. All rights reserved.
//

import Foundation
import UIKit

public extension UIView {

static var className: String {
let str = String(describing: type(of: self))
guard str.hasSuffix(".Type") else {
return str
}
return String(str[..<str.index(str.endIndex, offsetBy: -5)])
return String(describing: self)
}

func removeSubviewOf<T: UIView>(type: T.Type, animationDuration: TimeInterval? = nil) {
Expand Down
4 changes: 2 additions & 2 deletions UtilitiesCore/Resources/NibRegistrableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public protocol NibRegistrableView: UIView {
}

public extension NibRegistrableView {
static var nibName: String { return className }
static var reuseId: String { return className }
static var nibName: String { return Self.className }
static var reuseId: String { return Self.className }
static var nib: UINib { return UINib(nibName: nibName, bundle: Bundle(for: self)) }

static func instantiateFromNib() -> Self? {
Expand Down
22 changes: 22 additions & 0 deletions UtilitiesCoreTests/Extensions/TestNib.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="TestNib" customModule="UtilitiesCoreTests" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
</view>
</objects>
</document>
6 changes: 6 additions & 0 deletions UtilitiesCoreTests/Extensions/UIViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import XCTest
@testable import UtilitiesCore

class TestView: UIView { }
class TestNib: UIView, NibInstantiatable { }

class UIViewTests: XCTestCase {

Expand All @@ -25,4 +26,9 @@ class UIViewTests: XCTestCase {
contentView.removeSubviewOf(type: TestView.self)
XCTAssertFalse(contentView.subviews.contains { $0 is TestView })
}

func testClassName() {
let className = TestNib.instantiateFromNib(bundle: Bundle(for: TestNib.self))
XCTAssertNotNil(className)
}
}

0 comments on commit 07b5976

Please sign in to comment.