Xcode template doesn't pick the variable from popup - xcode

I'm writing an XCode template. Everything works perfectly fine if I use text value for the variable:
<dict>
<key>Identifier</key>
<string>appName</string>
<key>Required</key>
<string>true</string>
<key>Name</key>
<string>App name</string>
<key>Description</key>
<string>App name desc</string>
<key>Type</key>
<string>text</string>
<key>NotPersisted</key>
<string>true</string>
</dict>
But it doesn't, if I use popup:
<dict>
<key>Identifier</key>
<string>appName</string>
<key>Required</key>
<string>true</string>
<key>Name</key>
<string>App name</string>
<key>Description</key>
<string>App name desc</string>
<key>Type</key>
<string>popup</string>
<key>NotPersisted</key>
<string>true</string>
<key>Values</key>
<array>
<string>AppX</string>
<string>AppY</string>
</array>
</dict>
I'm accessing the variable like that:
class ___VARIABLE_appName:identifier___TestCase {}
Tried with:
___VARIABLE_appName:identifier___
___VARIABLE_appName___
___VARIABLE_appName:value___
and still nothing. I can of course just use text, but popup would be really better.

The solution for me was to create 2 folders (AppX and AppY) and store the duplicated templates inside them. The only thing that differs between these 2 files - is VARIABLE_appName - but by storing templates in different folders I remove the necessity to have it as a variable. So I hardcoded the value instead.
Instead of just Template1.swift I now have:
Folder AppX
-Template1.swift
Folder AppY
-Template2.swift

Related

Creating groups using a custom template xcode 8

I have successfully created an Xcode 8 template that will respond to these actions:
You already have a working project
You want to add your custom swift file to this project
Step by step, how to achieve that:
I have created under:
/Users/*YOUR_USER_NAME*/Library/Developer/Xcode/Templates/File Templates
The folder name Custom/Interactor.xctemplate
Files inside that folder:
___FILEBASENAME___Interactor
TemplateInfo.plist
TemplateIcon.png
TemplateIcon#2x.png
So when I right click and create new file, I will choose the custom file:
The above example works and creates my custom file:
What I am trying to achieve:
I am trying to create a group that will contain the new custom file. No need for an actual folder or complicated tasks, simply a group that contains the actual file.
So the end result will be:
Since there is no documentation explaining how to create a custom template I have used many references: ref1, ref2, ref3, ref4.
Here is the TemplateInfo.plist file:
<?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>MyCustomInteractor</string>
<key>Description</key>
<string>Custom interactor</string>
<key>Kind</key>
<string>Xcode.IDEKit.TextSubstitutionFileTemplateKind</string>
<key>Options</key>
<array>
<dict>
<key>Description</key>
<string>Custom interactor</string>
<key>Identifier</key>
<string>fileName</string>
<key>Name</key>
<string>Custom name</string>
<key>NotPersisted</key>
<true/>
<key>Required</key>
<true/>
<key>Type</key>
<string>text</string>
</dict>
<dict>
<key>Default</key>
<string>___VARIABLE_fileName:identifier___</string>
<key>Identifier</key>
<string>productName</string>
<key>Type</key>
<string>static</string>
</dict>
<dict>
<key>Default</key>
<string>___VARIABLE_fileName:identifier___Interactor</string>
<key>Description</key>
<string>The interactor name</string>
<key>Identifier</key>
<string>interactorName</string>
<key>Name</key>
<string>Interactor Name:</string>
<key>Required</key>
<true/>
<key>Type</key>
<string>static</string>
</dict>
</array>
<key>Platforms</key>
<array>
<string>com.apple.platform.iphoneos</string>
</array>
<key>SortOrder</key>
<string>99</string>
</dict>
</plist>
What I have tried:
I have tried to insert this answer into my TemplateInfo.plist but nothing happens. In my opinion it could be related to a scope issue - perhaps I am not inserting the Definitions or the Nodes keys in the right place. The xml Definitions and Nodes code snip I have been struggling with:
<key>Definitions</key>
<dict>
<key>___FILEBASENAME___Interactor.swift</key>
<dict>
<key>Group</key>
<string>Custom Interactor</string>
<key>Path</key>
<string>___FILEBASENAME___Interactor.swift</string>
</dict>
</dict>
<key>Nodes</key>
<array>
<string>___FILEBASENAME___Interactor.swift</string>
</array>
So where should I insert those keys or what am I doing wrong ?
Any help would be much appreciated.
Thanks.
you can create group as well as folder in project directory using this
<key>Swift</key>
<dict>
<key>Nodes</key>
<array>
<string>ViewController.swift:comments</string>
<string>ViewController.swift:imports:importCocoa</string>
<string>ViewController.swift:implementation(___FILEBASENAME___: UIViewController)</string>
<string>ViewController.swift:implementation:methods:viewDidLoad(override func viewDidLoad(\))</string>
<string>ViewController.swift:implementation:methods:viewDidLoad:super</string>
<string>ViewController.swift:implementation:methods:didReceiveMemoryWarning(override func didReceiveMemoryWarning(\))</string>
<string>ViewController.swift:implementation:methods:didReceiveMemoryWarning:super</string>
<string>Constant/CommonExtension.swift</string>
</array>
</dict>
and Definition just like this
<key>Definitions</key>
<dict>
<key>Base.lproj/Main.storyboard</key>
<dict>
<key>Path</key>
<string>Main.storyboard</string>
<key>SortOrder</key>
<integer>99</integer>
</dict>
<key>Group</key>
<array>
<string>Singletone</string>
</array>
<key>Constant/CommonExtension.swift</key>
<dict>
<key>Path</key>
<string>Constant/CommonExtension.swift</string>
<key>Group</key>
<array>
<string>Constant</string>
</array>
</dict>
</dict>
Incase this helps someone, Xcode 12.4 - project template.
<key>Nodes</key>
<array>
<string>ViewController.swift:comments</string>
<string>ViewController.swift:imports:importCocoa</string>
<string>ViewController.swift:implementation(___FILEBASENAME___: UIViewController)</string>
<string>ViewController.swift:implementation:methods:viewDidLoad(override func viewDidLoad(\))</string>
<string>ViewController.swift:implementation:methods:viewDidLoad:super</string>
<string>Info.plist:UIMainStoryboardFile</string>
<string>Info.plist:UIApplicationSceneManifest:UISceneStoryboardFile</string>
<string>Some/MainCoordinator.swift</string>
<string>Some/Other/TestClass.swift</string>
</array>
<key>Definitions</key>
<dict>
<key>Some/MainCoordinator.swift</key>
<dict>
<key>Group</key>
<array>
<string>Some</string>
</array>
<key>Path</key>
<string>MainCoordinator.swift</string>
</dict>
<key>Some/Other/TestClass.swift</key>
<dict>
<key>Group</key>
<array>
<string>Some</string>
<string>Other</string>
</array>
<key>Path</key>
<string>TestClass.swift</string>
</dict>
</dict>
The group is Some.
There's a file inside it.
There's also a subgroup inside it called Other.
And there's a file inside Other called TestClass.

Why isn't my document being recognized as a bundle in a minimally privileged environment?

I've got a OS X app that saves to a bundle. It works fine until I log out and then back in as a guest user and then it just shows up as a folder. The structure of the folder looks fine and has the correct extension, it's just not showing up as the custom UTI document.
I have changed the plist to say that the document is a bundle and changed it in the document types part of the target. Again, it is only not working when logging in as Guest User and so has been rejected from the App Store. Any ideas?
Here's the relevant section of "QTReview-Info.plist:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>movr</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>QTReviewIconRed</string>
<key>CFBundleTypeMIMETypes</key>
<array/>
<key>CFBundleTypeName</key>
<string>QTReview</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>com.protogylabs.qtreview</string>
</array>
<key>LSTypeIsPackage</key>
<integer>1</integer>
<key>NSDocumentClass</key>
<string>MyDocument</string>
<key>NSPersistentStoreTypeKey</key>
<string>Binary</string>
</dict>
The structure of the bundle is:
bundleFilename.movr (folder)
--Quicktime movie
--documentDictData
--annotationFiles (folder)
----image01.jpg
----image02.jpg

Creating sub-groups in XCode 4 Templates

While there is quite a lot of documentation and example for creating templates in XCode 3 converting them to XCode4 Templates is quite a nightmare...
First here is what i've found:
BorealKiss provides a nice tutorial for staters
Cocos2d has some very nice examples to make your templates more "evolved"
But all of them fail to answer this sample question:
How can someone create Folders Insider other Folders ?
For example if you want to have files inside a group you should write:
<key>Definitions</key>
<dict>
<key>File1.h</key>
<dict>
<key>Group</key>
<string>Group1</string>
<key>Path</key>
<string>File1.h</string>
<key>TargetIndices</key>
<array/>
</dict>
<key>File1.m</key>
<dict>
<key>Group</key>
<string>Group1</string>
<key>Path</key>
<string>File1.m</string>
</dict>
</dict>
<key>Nodes</key>
<array>
<string>File1.h</string>
<string>File1.m</string>
</array>
but how would you go for having Group1 inside Group2 for example.
I've tried many many things, playing with ancestors and all but nothing worked.
Any piece of advice or any documentation (I couldn't find any on those XCode templates) would be greatly appreciated.
I've tried many times modify the TemplateInfo.plist and I've also tried to make a sub group and put files in them. Finally I found the solution:
Definition section:
<key>Definitions</key>
<dict>
<key>main.h</key>
<dict>
<key>Path</key>
<string>main.h</string>
<key>Group</key>
<array>
<string>parent</string>
<string>child</string>
</array>
</dict>
</dict>
in the node section:
<key>Nodes</key>
<array>
<string>main.h</string>
</array>
The code above will create groups parent and child. and the main.h is in the child
Project
--parent
---child
----main.h
I've been struggling with this one myself too.
As a workaround I've created and added a folder in my TemplateInfo.plist location (in your case that should be folder named Group1). The folder layout (subfolders and files) are the same as I want them to be in my project source tree ( e.g folder 'Group1' has subfolder 'Group2', folder 'Group2' has files File1.h and File1.m etc).
Then I just add the root folder (Group1) in my TemplateInfo.plist file by defining it in the Definition section and by adding it to the Nodes section like this:
<key>Definitions</key>
<dict>
<key>Group1/</key>
<dict>
<key>Path</key>
<string>Group1/</string>
<key>TargetIndices</key>
<array/>
</dict>
<key>Nodes</key>
<array>
<string>Group1</string>
</array>
For anyone that needs help, this is on Xcode 12.4, this is a project template.
<key>Nodes</key>
<array>
<string>ViewController.swift:comments</string>
<string>ViewController.swift:imports:importCocoa</string>
<string>ViewController.swift:implementation(___FILEBASENAME___: UIViewController)</string>
<string>ViewController.swift:implementation:methods:viewDidLoad(override func viewDidLoad(\))</string>
<string>ViewController.swift:implementation:methods:viewDidLoad:super</string>
<string>Info.plist:UIMainStoryboardFile</string>
<string>Info.plist:UIApplicationSceneManifest:UISceneStoryboardFile</string>
<string>Base.lproj/Main.storyboard</string>
<string>Some/MainCoordinator.swift</string>
<string>Some/Other/TestClass.swift</string>
</array>
<key>Definitions</key>
<dict>
<key>Base.lproj/Main.storyboard</key>
<dict>
<key>Path</key>
<string>Main.storyboard</string>
<key>SortOrder</key>
<integer>98</integer>
</dict>
<key>Info.plist:UIMainStoryboardFile</key>
<string><key>UIMainStoryboardFile</key>
<string>Main</string>
</string>
<key>Some/MainCoordinator.swift</key>
<dict>
<key>Group</key>
<array>
<string>Some</string>
</array>
<key>Path</key>
<string>MainCoordinator.swift</string>
</dict>
<key>Some/Other/TestClass.swift</key>
<dict>
<key>Group</key>
<array>
<string>Some</string>
<string>Other</string>
</array>
<key>Path</key>
<string>TestClass.swift</string>
</dict>
</dict>

OSX Quicklook debugging

I am writing a quicklook plugin for an MPO file.
The plugin isn't that much of a problem, but the problem is trying to debug it. Apples documentation says that to debug you use
qlmanage -r <filename>
And I have. However, none of my breakpoints are matched. I assume this is as it hasn't matched my quicklook plugin with the type. Using mdl (or mdimport) i get a filetype of dyn.ah62d4rv4ge8046dt. Using that I get nothing. I have played around with the info.plist, as I assume that is the problem, and I have looked at other plugins to fix that, but still no breakpoints hit and it is not using my code.
My (important parts of) info.plist currently looks like this:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>QLGenerator</string>
<key>LSItemContentTypes</key>
<array>
<string>dyn.ah62d4rv4ge8046dt</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>QLGenerator</string>
<key>LSItemContentTypes</key>
<array>
<string>public.image.mpo</string>
</array>
</dict>
</array>
...
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
<string>public.image</string>
</array>
<key>UTTypeDescription</key>
<string>MPO Image file</string>
<key>UTTypeIconFile</key>
<string>MPO</string>
<key>UTTypeIdentifier</key>
<string>public.image.mpo</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>mpo</string>
</array>
</dict>
</dict>
</array>
Is there anything obviously that I am missing here, or any other reason that it is not executing my plugin?
Answering my own question, it will only debug something that is already in the /Library/QuickLook folder.
So now produced and available from here

Problem registering file type through UTIs

I'm using AquaticPrime for license generation in my app, and as the developer guide suggests I'm attempting to register a custom file extension, such that users can simply click on the license and my application will open it and can then verify the license.
To do this, I've added an exported UTI declaration to my Info.plist as follows:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeDescription</key>
<string>MyApp License File</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.xml</string>
</array>
<key>UTTypeIdentifier</key>
<string>com.mycompany.myapplicense</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>myapplicense</string>
</array>
</dict>
</dict>
</array>
However, when I double-click on a file with that extension it doesn't open in MyApp, and nor does MyApp appear as one of the recommended apps to open the file type with. As well, when viewing the Info panel for the file, the filetype description as specified above doesn't appear.
Can anyone see anything wrong with my UTI declaration, or is there something else that I've missed?
Thanks
You also need a CFBundleDocumentTypes declaration.
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFile</key>
<string>MyAppLicenseIcon</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>NSDocumentClass</key>
<string>MyAppLicenseHandler</string>
<key>LSItemContentTypes</key>
<array>
<string>com.mycompany.myapplicense</string>
</array>
</dict>
</array>
To add to this, in my case I've had to also make sure that I was entering the proper format UTI as such:
<key>UTTypeConformsTo</key>
<array>
<string>public.xml</string>
my file being a simple .plist, it still conforms to xml. You need to make sure you know which UTI format you conform to.

Resources