Why is Xcode not prefixing filenames? - xcode

When I start an iOS single view application project, the AppDelegate files and ViewController files are not prefixing with the project name like they used to.
files names are as follows when I open a new project:
AppDelegate.h
AppDelegate.m
MainStoryBoard.storyboard
ViewController.h
ViewController.m
Why is this?

You have to add it manually. When you create a new project just fill out the "Class Prefix" field on the screen where you name the project/bundle id/ etc..
Just add your prefix where I wrote "THIS IS THE PREFIX" in the screenshot below
If you want to add a prefix after you've created your project, you can do so in the file inspector on Xcode's right pane:

Personally, I prefer not to prefix class names within an application.
When you are writing code for libraries, or custom classes, or categories, they are recommended, as there aren't namespaces in Objective-C.
But for application classes, I find they are just noise. Looking down a list of files that all have the same three letters in the front makes it just a bit harder to find what I'm looking for.
I mean, are you really going to have more than one class called AppDelegate? I'm all for full and descriptive naming of my classes, but prefixes for all the classes doesn't help me.
If it helps there are a few conventions for writing code. Search and you'll find them. Here are mine, for example.
You don't have to follow them, but pick a style and be consistent with it.

XCode 8 does NOT have the 'Class Prefix' field. It only has 'Product Name' and this does not ripple down to the view controller or the app delegate. I think 8.3 has bugs.

Class Prefix is file & template business. For the sake of organised files in a project it makes sense to have filenames that express their contents.
The workflow to achieve that was actually simplified with the Class Prefix field in the File inspector panel while your project name is active (clicked) in the file browser.
When there is a class prefix set the class name field when creating new files is predefined. That way you can choose file by file (class by class) if you want to use it and class name and file name will result in similar name scheme.

Related

How to document private (non public interface) by using appleDoc?

recently I have learned how to use the appleDoc to do the documentation for my iphone project.
But what I realize is that AppleDoc only scan the head file of each class and based on the special comment format it creates the docSet and html.
My question is that how to let the AppleDoc looking after the .m file as well. Because for classes like viewController, quite a few logic are in the .m sectors and not be exposed in the head file. (I am asking this is because in Xcode5 if you hover over a private method and press "option" button xcode does show you a hover which contain the special comment you made. That's how I guess that there must be a way to transfer these description/comment into the docSet).
Anybody has some idea please help to give me some answer.
Thanks
Finally I found out there was a line in the script command which you need to remove.
It will include all the "*.m" files where all the "private" interface comments are kept.

Why does Xcode 5 assistant editor defaults to .m file

I realized that when launching assistance editor while working on a XIB file no longer opens the header file by default, instead it shows the implementation file. Is there a new workflow going on I am not aware of? While in the implementation file I can only seem to be able to add IBActions. What is the "new" way to create IBOutlets? Switching to header file each time??
My 2 Cents:
When you create a new class using the Xcode templates, it usually provides a class extension in the implementation file for private properties. It makes a lot of sense to actually link the IBOutlets and IBActions there, because in most cases they are only ever used within the class itself.
The only exception to this that crosses my mind right now is UIView subclasses, and especially UITableViewCell. A lot of developers access the IBOutlets directly in cellForRowAtIndexPath:.
Apple engineers' message:
Encapsulate your IBOutlets & IBActions whenever possible!

iPhone SDK: Localization of external class files?

I am adding some external classes to my already-localized project that include their own localization strings. For some reason the localization isn't working in these classes. It should be noted that I am not copying the external class files to my project, just adding a reference to them. I thought the problem could be that the external string file couldn't have the same name as the projects string file -- Localizable.strings -- so I changed it to something unique for the class. This didn't help. I also tried dragging the classes string files directly to the "Copy Bundle Resources" of my project to make sure that the strings in the bundle. Still no luck.
Interestingly, if I add these localized classes to a different project that isn't yet localized -- e.g. there isn't any Localizable.strings file in the project -- the class localizations work fine.
Suggestions?
You should use NSLocalizedStringFromTable instead of NSLocalizedString to extract strings from tables other than the default Localizable.strings.

How to find implementation file made by Interface Builder?

I made an object in Interface Builder. Then I told it to write the class files. But when I go to XCode I can't find the implementation or header files. How can I edit the implementation file?
The class files are wherever you saved them. So, go there, move them somewhere else if you want, and then add them to your Xcode project.

Why can't I see a Managed Object Class file template in Xcode?

I created a .xcdatamodel Managed Object Model file in Xcode. I selected that file in Groups & Files. Then I go to File > New... > and nowhere in the iPhone Templates / Cocoa Touch Class templates I see the "Managed Object Class" file template.
Does anyone know what can be wrong?
I usually need to also select the entities for which I want to generate the class files.
In Xcode 4, select the entity in the xcdatamodeld, then choose Editor Menu > Create NSManagedObject Subclass
If you are wanting to subclass NSManagedObject then I would highly recommend talking a look at mogenerator (github). It will autogenerate the subclasses for you AND keep them in sync as you update your model. It also has the concept of machine classes vs. human classes so that you can add convenience methods, etc. without your code being stepped on each time you update your model.
I've seen this problem before as well. Solution for me was to click on a non-data model file (in Groups & Files) and then click back on the versioned data model file (and entity within it) and then try File -> New File. Alternatively, restarting xcode, selecting the data model file (and entity within it) and then trying File -> New File also worked for me.
Click On the top left where it says "Simulator 3.1.2 | debug". Change it to "IPHONE Device 3.1.2 (BASE SDK)... voila. (SAMS iphone in 24hrs?? lots of typos and incomplete procedures!)
Managed Object Class file template can be seen under "Core Data" section of new file creation option of XCode 4.
The following screenshot depicts it.
Thanks,
prodeveloper.

Resources