Skip to content

Commit

Permalink
R.nib.myNib(owner: nil) now loads the first view (mac-cain13#417)
Browse files Browse the repository at this point in the history
* `R.nib.myNib(owner: nil)` now loads the first view

`R.nib.myNib()` that loaded the UINib is removed. The alternative to that is `UINib(resource: R.nib.myNib)`

* Bring back the old methods as deprecated

for easier migration

* Remove development team
mac-cain13 authored Jun 15, 2018
1 parent 8f2b450 commit 3a99d77
Showing 4 changed files with 47 additions and 76 deletions.
50 changes: 2 additions & 48 deletions ResourceApp/ResourceApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -493,7 +493,6 @@
D55C6CB51B5D757300301B0D /* Frameworks */,
D55C6CB61B5D757300301B0D /* Resources */,
89BF8D4EC08D38DB6564C369 /* [CP] Embed Pods Frameworks */,
ADB91CF666C6624CD5A00F13 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
@@ -513,7 +512,6 @@
D55C6CCC1B5D757300301B0D /* Frameworks */,
D55C6CCD1B5D757300301B0D /* Resources */,
45EF1C0CF8F1496731872E16 /* [CP] Embed Pods Frameworks */,
7291DEE28E5CA956526A9741 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
@@ -535,7 +533,6 @@
DEF559941CA4873D009B8C51 /* Frameworks */,
DEF559951CA4873D009B8C51 /* Resources */,
21DD8AD3CCA3AFB82438FB4E /* [CP] Embed Pods Frameworks */,
0085D428CB6B6989667E7846 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
@@ -712,21 +709,6 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
0085D428CB6B6989667E7846 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-Shared-ResourceApp-tvOS/Pods-Shared-ResourceApp-tvOS-resources.sh\"\n";
showEnvVarsInLog = 0;
};
21DD8AD3CCA3AFB82438FB4E /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@@ -765,21 +747,6 @@
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-Shared-ResourceAppTests/Pods-Shared-ResourceAppTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
7291DEE28E5CA956526A9741 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-Shared-ResourceAppTests/Pods-Shared-ResourceAppTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
89BF8D4EC08D38DB6564C369 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@@ -818,21 +785,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
ADB91CF666C6624CD5A00F13 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-Shared-ResourceApp/Pods-Shared-ResourceApp-resources.sh\"\n";
showEnvVarsInLog = 0;
};
C0FE64906E443AEB878A317C /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@@ -1150,6 +1102,7 @@
baseConfigurationReference = 22ACD120062243785169391F /* Pods-Shared-ResourceApp.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = ResourceApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -1164,6 +1117,7 @@
baseConfigurationReference = 3677277BC1C4F3F77310381B /* Pods-Shared-ResourceApp.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = ResourceApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "NO"
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
@@ -29,7 +29,9 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
skipped = "NO"
parallelizable = "YES"
testExecutionOrdering = "random">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D55C6CCE1B5D757300301B0D"
1 change: 1 addition & 0 deletions ResourceApp/ResourceAppTests/NibTests.swift
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ class NibTests: XCTestCase {
}

func testRelativeToProjectGroup() {
XCTAssertTrue(R.nib.relativeToProject(owner: nil) != nil)
XCTAssertTrue(R.nib.relativeToProject.firstView(owner: nil) != nil)
}

66 changes: 40 additions & 26 deletions Sources/RswiftCore/Generators/NibStructGenerator.swift
Original file line number Diff line number Diff line change
@@ -35,6 +35,11 @@ private let Ordinals = [
struct NibStructGenerator: StructGenerator {
private let nibs: [Nib]

private let instantiateParameters = [
Function.Parameter(name: "owner", localName: "ownerOrNil", type: Type._AnyObject.asOptional()),
Function.Parameter(name: "options", localName: "optionsOrNil", type: Type(module: .stdLib, name: SwiftIdentifier(rawValue: "[NSObject : AnyObject]"), optional: true), defaultValue: "nil")
]

init(nibs: [Nib]) {
self.nibs = nibs
}
@@ -65,7 +70,41 @@ struct NibStructGenerator: StructGenerator {
.map { nibVar(for: $0, at: externalAccessLevel, prefix: qualifiedName) }
let nibFunctions: [Function] = groupedNibs
.uniques
.map { nibFunc(for: $0, at: externalAccessLevel, prefix: qualifiedName) }
.flatMap { nib -> [Function] in
let qualifiedCurrentNibName = qualifiedName + SwiftIdentifier(name: nib.name)

let deprecatedFunction = Function(
availables: ["*, deprecated, message: \"Use UINib(resource: \(qualifiedCurrentNibName)) instead\""],
comments: ["`UINib(name: \"\(nib.name)\", in: bundle)`"],
accessModifier: externalAccessLevel,
isStatic: true,
name: SwiftIdentifier(name: nib.name),
generics: nil,
parameters: [
Function.Parameter(name: "_", type: Type._Void, defaultValue: "()")
],
doesThrow: false,
returnType: Type._UINib,
body: "return UIKit.UINib(resource: \(qualifiedCurrentNibName))"
)

guard let firstViewInfo = nib.rootViews.first else { return [deprecatedFunction] }

let newFunction = Function(
availables: [],
comments: [],
accessModifier: externalAccessLevel,
isStatic: true,
name: SwiftIdentifier(name: nib.name),
generics: nil,
parameters: instantiateParameters,
doesThrow: false,
returnType: firstViewInfo.asOptional(),
body: "return \(qualifiedCurrentNibName).instantiate(withOwner: ownerOrNil, options: optionsOrNil)[0] as? \(firstViewInfo)"
)

return [deprecatedFunction, newFunction]
}

let externalStruct = Struct(
availables: [],
@@ -86,26 +125,6 @@ struct NibStructGenerator: StructGenerator {
)
}

private func nibFunc(for nib: Nib, at externalAccessLevel: AccessLevel, prefix: SwiftIdentifier) -> Function {
let nibName = SwiftIdentifier(name: nib.name)
let qualifiedName = prefix + nibName

return Function(
availables: [],
comments: ["`UINib(name: \"\(nib.name)\", in: bundle)`"],
accessModifier: externalAccessLevel,
isStatic: true,
name: SwiftIdentifier(name: nib.name),
generics: nil,
parameters: [
Function.Parameter(name: "_", type: Type._Void, defaultValue: "()")
],
doesThrow: false,
returnType: Type._UINib,
body: "return UIKit.UINib(resource: \(qualifiedName))"
)
}

private func nibVar(for nib: Nib, at externalAccessLevel: AccessLevel, prefix: SwiftIdentifier) -> Let {
let structName = SwiftIdentifier(name: "_\(nib.name)")
let qualifiedName = prefix + structName
@@ -121,11 +140,6 @@ struct NibStructGenerator: StructGenerator {
}

private func nibStruct(for nib: Nib, at externalAccessLevel: AccessLevel) -> Struct {
let instantiateParameters = [
Function.Parameter(name: "owner", localName: "ownerOrNil", type: Type._AnyObject.asOptional()),
Function.Parameter(name: "options", localName: "optionsOrNil", type: Type(module: .stdLib, name: SwiftIdentifier(rawValue: "[NSObject : AnyObject]"), optional: true), defaultValue: "nil")
]

let bundleLet = Let(
comments: [],
accessModifier: externalAccessLevel,

0 comments on commit 3a99d77

Please sign in to comment.