मैं एक फ़ाइल टेम्पलेट बनाने का प्रयास कर रहा हूं जो एक View.swift फ़ाइल (UIView का उपवर्ग) और उक्त View.swift फ़ाइल से जुड़ा एक XIB उत्पन्न करता है।

मैं दोनों को ठीक से जोड़ सकता हूं, लेकिन किसी कारण से, मेरा XIB नहीं है... एर... UIKit अनुकूल? मुझे यकीन नहीं है कि इसका वर्णन कैसे किया जाए। मुझे उम्मीद है कि मेरी XIB फ़ाइल इस तरह लोड होगी:

Expected XIB in the interface builder

हालांकि, इसके बजाय यह इस तरह लोड होता है:

Current XIB in the interface builder

यहाँ प्रासंगिक View.swift फ़ाइल, XIB फ़ाइल के लिए कॉन्फ़िगरेशन और TemplateInfo.plist . है

देखें.स्विफ्ट

import UIKit

class ___VARIABLE_sceneName___View: ___VARIABLE_cocoaSubclass___ {
    //MARK: XIB Outlets
    @IBOutlet var contentView: ___VARIABLE_cocoaSubclass___!

 // MARK: Object lifecycle
override init(frame: CGRect) {
    super.init(frame: frame)
    setup()
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    setup()
}

// MARK: Setup

private func setup() {
Bundle.main.loadNibNamed("___VARIABLE_sceneName___", owner: self, options: nil)
        addSubview(contentView)
        contentView.frame = self.bounds
        contentView.autoresizingMask = [.flexibleHeight, .flexibleHeight]    
}

XIB

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11134" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11134"/>
    </dependencies>
    <objects>
        <customObject id="-2" userLabel="File's Owner" customClass="___VARIABLE_sceneName___View" customModuleProvider="target">
            <connections>
                <outlet property="contentView" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
            </connections>
        </customObject>
        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
        <customView id="Hz6-mo-xeY">
            <rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
        </customView>
    </objects>
</document>

TemplateInfo.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>DefaultCompletionName</key>
    <string>MyScene</string>
    <key>Description</key>
    <string>This generates a new View for a View Controller.</string>
    <key>Kind</key>
    <string>Xcode.IDEKit.TextSubstitutionFileTemplateKind</string>
    <key>Options</key>
    <array>
        <dict>
            <key>Name</key>
            <string>Subclass Of</string>
            <key>Values</key>
            <array>
                <string>NSView</string>
            </array>
            <key>FallbackHeader</key>
            <string>#import &lt;Cocoa/Cocoa.h&gt;</string>
            <key>Default</key>
            <string>NSView</string>
            <key>Type</key>
            <string>class</string>
            <key>Identifier</key>
            <string>cocoaSubclass</string>
        </dict>
        <dict>
            <key>Description</key>
            <string>The name of the scene to create</string>
            <key>Identifier</key>
            <string>sceneName</string>
            <key>Name</key>
            <string>New Scene Name:</string>
            <key>NotPersisted</key>
            <true/>
            <key>Required</key>
            <true/>
            <key>Type</key>
            <string>text</string>
        </dict>
        <dict>
            <key>Default</key>
            <string>___VARIABLE_sceneName:identifier___</string>
            <key>Identifier</key>
            <string>productName</string>
            <key>Type</key>
            <string>static</string>
        </dict>
        <dict>
            <key>Default</key>
            <string>___VARIABLE_sceneName:identifier___View</string>
            <key>Description</key>
            <string>The view controller name</string>
            <key>Identifier</key>
            <string>viewControllerName</string>
            <key>Name</key>
            <string>View Controller Name:</string>
            <key>Required</key>
            <true/>
            <key>Type</key>
            <string>static</string>
        </dict>
        <dict>
            <key>Default</key>
            <string>___VARIABLE_sceneName:identifier___Components</string>
            <key>Description</key>
            <string>The components name</string>
            <key>Identifier</key>
            <string>componentsName</string>
            <key>Name</key>
            <string>Components Name:</string>
            <key>Required</key>
            <true/>
            <key>Type</key>
            <string>static</string>
        </dict>
        <dict>
            <key>Identifier</key>
            <string>XIB</string>
            <key>Name</key>
            <string>Also create a XIB file</string>
            <key>Description</key>
            <string>Use a Xib?</string>
            <key>Type</key>
            <string>checkbox</string>
            <key>Required</key>
            <true/>
            <key>Default</key>
            <false/>
            <key>NotPersisted</key>
            <true/>
        </dict>
        <dict>
            <key>Identifier</key>
            <string>languageChoice</string>
            <key>Required</key>
            <true/>
            <key>Name</key>
            <string>Language:</string>
            <key>Description</key>
            <string>The implementation language</string>
            <key>Type</key>
            <string>popup</string>
            <key>Default</key>
            <string>Swift</string>
            <key>Values</key>
            <array>
                <string>Swift</string>
            </array>
            <key>MainTemplateFiles</key>
            <dict>
                <key>Swift</key>
                <string>___FILEBASENAME___View.swift</string>
            </dict>
            <key>AllowedTypes</key>
            <dict>
                <key>Swift</key>
                <array>
                    <string>public.swift-source</string>
                </array>
            </dict>
        </dict>
    </array>
    <key>Platforms</key>
    <array>
        <string>com.apple.platform.iphoneos</string>
    </array>
    <key>SortOrder</key>
    <string>1</string>
    <key>Summary</key>
    <string>This generates a new View for the View Controller of the same name.</string>
</dict>
</plist>

टेम्प्लेट कंटेनर फ़ोल्डर का नाम NSViewXIBSwift है।

-1
Misha Stone 27 मई 2019, 10:50

1 उत्तर

सबसे बढ़िया उत्तर

जब आप अपना xib बनाते हैं, तो iOS xib में अंतर करें:

enter image description here

MacOS xib से:

enter image description here

2
matt 27 मई 2019, 08:01