Objective-C, Transitioning from .nib to .storyboard - xcode

I'm trying to update my application from using .nibs to the more recent .storyboard format on OS X. I'm not exactly sure what the best method of accomplishing this would be.
Currently I have both the old MainMenu.nib and Main.Storyboard in my project. It's easy enough for me to manually copy items from the .nib to the .storyboard, although how do I tell XCode to start using my .storyboard instead of the .nib? Is it possible to use both in the same project? Any suggestions welcomed.

although how do I tell XCode to start using my .storyboard instead of the .nib?
If you no longer want to use MainMenu.nib at all, then you set the NSMainStoryboardFile key in your Info.plist (and delete the NSMainNibFile key). That way, the storyboard file is used at launch.
Info.plist keys are documented here:
https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/GeneralPurposeKeys.html

Related

Xcode 13 AppleScript framework can't connect UI to Applescript code

Trying to create an AppleScript executable for MacOS 11.5 using Xcode 13 with AppleScript framework. Right out of the box (no processing on my part), the delegate icon on the IB display does not point to the default AppleScript code. This is clear since the outlet list for the icon claims that the AppDelegate does not have an outlet named theWindow whereas the AppleScript code clearly does. I've been trying for days to do a simple Hello World sort of thing and have been completely unable to connect UI elements with the "delegate", especially action elements. Am I missing some configuration step or is this a Xcode 13 bug? In examples I've seen on YouTube for creating this for this kind of simple thing the normal Xcode storyboard techniques work as expected (e.g. ctrl drag) but none of them used Xcode 13. Any insight is appreciated.screenshot of IB delegate binding
For future reference, this is starting to pop up on various forums, and appears to be a bug.
The normal signatures for creating IB outlets and action handlers is not being recognized by the Interface Editor. Existing projects - including the base Xcode templates - will build normally, although the editor shows warnings that outlets/actions don’t exist.
There isn’t much of a workaround other than creating objects programmatically or going back to an earlier version of Xcode until a fix is issued.
Update:
As mentioned in other answers and comments, the IB outlet and action handler connection bug has been fixed in Xcode 14, but the AppleScript application and Automator action templates are no longer included.
Custom templates can be created (or copied from an earlier version of Xcode from its Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/macOS/Other folder) and placed in a custom templates folder in your user’s Library folder at ~/Library/Developer/Xcode/Templates/. You can name this template folder whatever you want, such as "My Templates", where it will be shown in the template chooser.
Each template contains a TemplateInfo.plist file with various settings for that template - a complete tutorial is beyond the scope of this topic, but the value for the key "Identifier" in the base dictionary can be used to give your template a custom identifier, such as "com.my.cocoaApplicationAppleScript".
I am using 13.4.1 and the bug is still there.
I am wondering its its worth trying version 14 beta to see if it has been resolved
Playing around with this a little, I did find a workaround, though it's not entirely satisfactory. It amounts to editing the xib xml directly. For example, say you have button in the GUI that you'd like to reference in your script. First, create a property in the AppleScript like so:
property myButton : missing value
Then navigate to the xib file in Xcode, right-click on the xib in the file navigator and choose Open as... → Source Code (the default is "interface Builder XIB Document", which you'll want to return to later). This will show you the xml that underlies the graphical representation. First, search through the text to find the button in question. It will look something like:
<window title="Window" ...>
...
<view key="contentView" id="...">
...
<subviews>
<button ... id="xok-ud-pwL">
...
</button>
</subviews>
</view>
</window>
You want to get the id from the button, which in this case is "xok-ud-pwL". Then go back up to the top of the xml and look for the AppDelegate entry, which will look like:
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
You'll want to edit this so that it looks like the following:
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="myButton" destination="xok-ud-pwL" id="gn6-Ea-hra"/>
</connections>
</customObject>
property should be the name of the property in the script
destination should be the id value of the button you want to connect
id should be a random and unique alphanumeric in 3-2-3 format
This will create an outlet connection between the property and the GUI element. It will even appear in the pop-up menu for the appDelegate so that you can reconnect it graphically. However, if you delete the connection in IB, Xcode will delete the entry from the xml, so you'll have to start again from scratch.
Still buggy, but...
The Release Candidate version of Xcode 14 patch it !
"Fixed an issue with outlet and action connections to AppleScript-based AppDelegates. (83373726) (FB9643535)"
But, you can't create a new project.
If you could find this old Template directory from an Xcode version < 14, you could add again the template AppleScript App.
Quit Xcode
Copy source template from version < 14 (I used v12.4):
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/macOS/Other/AppleScrip App.xctemplate
Copy to the destination folder:
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/Other/
Restart Xcode
I think Apple wants to remove AppleScript in next version of MacOS
Tested on Xcode 14 (14A309) 11 Sept 2022!
Regards
Laurent

Problems setting application icon with QT 5.3 on Mac

I've been trying to set my application's icon following the directions here:
http://qt-project.org/doc/qt-5/appicon.html
If I understand correctly, the process should be fairly simple:
Create an icon file (FlySightViewer.icns) using iconutil. I followed the directions here: https://stackoverflow.com/a/20703594/443822.
Add ICON = FlySightViewer.icns to the .pro file.
However, when I follow these steps, the icon remains the default Qt application icon. I've tried deleting the app bundle and build folder, since I've read that these are sometimes not rebuilt through the usual process. This doesn't seem to resolve the issue.
Looking a bit deeper, when I run qmake from Qt Creator, the generated Makefile contains several instances of FlySightViewer.icns, including this line:
#$(COPY_FILE) ../flysight-viewer-qt/src/FlySightViewer.icns FlySightViewer.app/Contents/Resources/FlySightViewer.icns
The file ../flysight-viewer-qt/src/FlySightViewer.icns seems to be right where I expect it to be. However, when I build the project and look inside the app bundle, the icon is nowhere to be found. The only thing in the Resources folder is empty.lproj.
So it seems to me that the icon isn't appearing as expected because it is not being copied to the app bundle, but I have no idea why that might be.
Any help would be appreciated. I realize this is a fairly common question, but none of the answers I've found here seems to have helped.
Thanks for your time!
Add this line into .pro file:
QMAKE_INFO_PLIST = Info.plist
Then create the .plist and set the icon name there. I won't paste an example .plist because it's quite large, but you can see how it's done by right-clicking a random app and selecting "show package contents".
With older versions of Qt, I settled on changing the icon manually. However, the most recent version of Qt (or macdeployqt) seems to have fixed the problem, so I no longer need to set the icon manually.

MonoDevelop is not generating IB outlets for my MonoMac project

I am getting back in to MonoMac, and straight away, experiencing problems.
I have added my outlets and actions to my XIB files, and linked them with IB controls, saved my XIB, and returned to MonoMac, and it is not regenerating the C# files, so the bindings are not linked - I cannot use them.
What happening? I am using the latest stable versions of everything (MonoMac did all its updates).
Thanks
This happens sometimes. I you are using a XIB file generated by MonoMac as default resources, you just need to close both MonoDevelop and Xcode, go to your project folder and clear the bin and object folders. Run the MonoMac, double click your XIB file, edit it in Xcode, press the Command+S buttons 2 or 3 times to make sure the files get changed so MonoDevelop will sync them, and your C# files will get generated...
But I had a situation that this didn't work and I couldn't figure it out and that was when I started an Empty MonoMac Project and added an Empty XIB file to it! The C# files do not get Sync after 5 tries and I didn't waste my time trying to fix it. Created a Document MonoMac project, deleted unneeded files and continued my work.
Hope it helps.

Monodevelop migrate 2.8 didn't add .h files

I just upgrade my MonoDevelop to the latest version (2.8). I also installed XCode4, since it's fully supported now. When opening my solution (which consists of several projects) I was asked to migrate my solution. I did this and saved everything.
However, I think something is missing. When I open the .xib file, the project on the right doesn't show .h files, like shown in the tutorial.
It also shows warnings that the outlets were not found in XCode.
When I add a new screen, it creates the .h file as it should and shows this in XCode. However all existing screens don't have these files, which makes it impossible to add/change outlets.
How can I fix this.
Check that your classes you expect to see in Xcode have explicit [Register("SomeName")] attributes, which register them with a name usable from Xcode/Obj-C/IB.
I would expect an imported project to have those attributes already, since they're required for xibs to be able to load the classes by name, but you could maybe have got away without those attributes by using outlets on "File's Owner".

Can't create iPad XIB with Xcode 4

Alright, I have a problem on my hands. I'm trying to convert my project to a universal app for the iPhone and the iPad. I'm trying to make iPad-specific versions of my XIB files. As it's not possible to Create iPad version using autoresizing masks in Xcode 4, I assumed I'd just be able to pop my XIB into Xcode 3's version of IB, and let that do the magic. No dice. Here's the error I get when i try to open the XIB file in IB:
To be honest I don't know where to proceed from here. I guess I could just resize my views manually, but that's quite tedious and I don't really have the time to be doing that. Any ideas?
Alright, I figured out a rather convoluted workaround.
First of all, duplicate your original project and then select your project info. Right-click on your target, and select "Duplicate".
Xcode will then pop up this message. Select "Duplicate and Transition to iPad".
Now Xcode converts the XIB files for you, and presents you with an iPad resources folder.
Now open these XIB files in the Finder, and append ~ipad after the file name.
After doing so, copy these XIB files back into your original project, and then turn your project into a universal project by selecting from the dropdown in your target settings.
And you're done. I found that really convoluted, and I'm hoping Apple can fix this huge usability problem soon.
This should not happen. One way to fix this problem would be t completely remove the Xcode 4 Installation and re install it from scratch . And then re install it.
Use the following command to uninstall and re install Xcode 4
sudo [xcode-path]/Library/uninstall-devtools --mode=all
PS: If you are creating projects in Xcode 4 that you also want to open in Xcode 3 make sure you keep Document Versioning section to Interface Builder 3.1

Resources