In Xcode 6, how do I change the default template Xcode choses when creating a new file.
Right now, the template chooser (first screen when creating a new file) defaults to:
OS X - Source - Cocoa Class
I want it to default to:
IOS - Source - Cocoa Touch Class
You'd think the when you create an IOS project, Xcode would then default to choosing IOS templates ... but, it doesn't appear to do that.
Related
I am learning the document-based app architecture of macOS app development, but am confused about it.
I created a document-based app in Xcode. The app template created a simple document-based app. It can run, and will create a new document automatically when it is run.
My question is: How does this app start the document architecture? I suppose that there should be some code like the following:
NSDocumentController *docController;
docController = [NSDocumentController sharedDocumentController];
[docController newDocument:self];
But I can't find any such code in the created app. The - (void)applicationDidFinishLaunching: method in the app delegate is empty. Also, there is not any NSDocumentController object in the main nib file.
So, how does this app know that it should use the document architecture, initialize a NSDocumentController, and then create a new document?
how does this app know that it should use the document architecture, initialize a NSDocumentController, and then create a new document?
I’m unclear about the inner workings of Xcode, but it appears that in the app’s info.plist CocoaNSDocumentClass has to be set to Document and Role has to be set to Editor (or Viewer, None, or Shell) in order for the document to be created. In your demo try deleting either one or both of these lines in the plist and see if the app still works. Both settings are located on the second level of Document types. In my experience, deleting either of these lines breaks the app and restoring the correct setting fixes it. In a programmatically created document-based app (no nib) and compiling with Terminal the following errors are generated when I go inside the bundle and run the executable after deleting one or the other info.plist settings mentioned above.
2020-02-11 19:31:48.294 nsdoc_demo[1606:658926] NSDocumentController Info.plist warning: The values of CFBundleTypeRole entries must be 'Editor', 'Viewer', 'None', or 'Shell'.
2020-02-11 19:38:46.355 nsdoc_demo[1748:680819] -[NSWindowController loadWindow]: failed to load window nib file 'Document'.
Xcode (with Document.xib) generates the following error when CocoaNSDocumentClass is not set:
2020-02-11 16:22:03.022602-0600 docExpt[1166:428702] The DocumentType type doesn't map to any NSDocumentClass.
In my experience the source code can be ok, but if the info.plist is not set correctly a document-based app won’t work as expected.
When I include a WebView component on a form in my Objective C project in XCode7 for a Cocoa application on OSX and try to compile, it compiles and then has a runtime error of:
NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (WebView) for key (NS.objects); the class may be defined in source code or a library that is not linked
What's the fix?
In XCode7, if you use a WebView widget, you have to add the framework. Go to the Project Navigator and click the first icon, which is your project icon. In the middle of your screen on that IDE then, you'll see General > Linked Frameworks and Libraries. Click the + and add WebKit.framework. Now when you compile, the linkage will be there and it will work.
The drawback I think is that it says it's a 10.11 component, and so if I want to deploy my app to a 10.9 system or 10.10 system, it won't work. I'm not 100% certain of this without testing, however, but do have this hunch.
ADDENDUM:
I set my project to be 10.8 compliant and then found I can run just fine on 10.8 all the way to the latest OSX.
if I remember correctly, in xCode 5 and below, the "New File" option for project navigator included a template to create an extension for an existing class. This option was next to "Cocoa Touch Class" and allowed to enter a base class name. The generated file had a form like "NSString+JSON.h"
How do I create class extensions in xCode 6? Do I start with a class file and then modify it and it's name to include category name?
The process is similar to this question I answered:
How to create Objective-C Protocol in new version of XCode Version 6.0.1 (6A317) for iOS
Select New File > Objective-C File > Choose Extension from the dropdown.
I can't understand how I can localize today extensions, I want to create the Localize.strings file like a normal xcode project that for example have this string:
.en
"Apple" = "Apple"
.it
"Apple" = "Mela"
and I also want to know how I can localize the iOS 8 Today Extensions widget name.
I have tried to create a Strings File in Xcode, and I have tried to insert this:
"CFBundleDisplayName" = "App Name";
but the name doesn't change...
Add LSHasLocalizedDisplayName = YES to Info.plist file and add your localizations to InfoPlist.strings which you have to place under the language.proj folder per languages, for example de.lproj for German versions.
Before testing:
- Clean the project
- Remove the application from the simulator.
- Add language.proj folder references to extension's Supporting files part - to include them inside Copy bundle resources section in Build Phases of your extension target.
For strings in your containing app and Today Widget can share the same localization files. You can simply select Localizable.string, and in the File inspector check your today widget target in Target Membership. Then all your NSLocalizedString in the today widget share the same one with the containing localization strings.
For the today widget application name, then just add an InfoPlist.strings file, and
"CFBundleDisplayName" = "Translated Name";
"CFBundleName" = "Translated Name";
Just run your containing app for testing.
Xcode 6 Beta 4 using Swift.
I use localization in my project and I have experience in localization from Xcode 5.
Localization in program code using NSLocalizedString() works fine.
Localization of Info.plist strings work fine, too.
When it comes to localize the strings from Interface Builder it only works in Interface Builder preview but not in simulator and not on my device (iPhone 5S).
Am I missing something or can anyone confirm this as a bug in in Xcode 6 Beta 4?
It seems like the problem is with the size classes.
If "Use Size Classes" checkbox is enabled for storyboard, the Xcode actually generates 3 versions of it ("<Name>.storyboard", "<Name>~ipad.storyboard" and "<Name>~iphone.storyboard").
So iOS just tries to load .strings file which name matches the name of active storyboard (<Name>~iphone.strings in case app is running on the iPhone). And being not able to find that file, it falls back to Base localization.
There are a couple of ways to work around this bug:
The most obvious one. Just disable size classes for the storyboard.
If you need size classes, you can add localized <Name>~iphone.strings and <Name>~ipad.strings files to the project manualy and copy your translations over.
Apple release notes of XCode 6 GM covers this :
Localization:
A storyboard or XIB will not localize correctly if all of the following three conditions are true:
The storyboard or XIB uses size classes.
The base localization and the build target are set to Universal.
The build targets iOS 7.0.