Comments style for xCode - ios

How shall I write (what style) the comments for public methods and properties in my classes so they would be visible in Quick Help window the same way they are for built in methods?
The absence of strong typed array in iOS creates bunch of issues for me, especially when a method accepts a NSArray*, if I wrote it 6 months ago, then I need for sure to go in that method and check what are actual types that must be stored in that array.
Thx

Yes, you will have to regenerate the documentation whenever you want a change. Xcode does not pick up documentation on the fly based on your comments like Visual Studio can. This is confirmed by a comment in the question I linked to:
Xcode's Quick Help uses your installed documentation sets to display its contents. Unless you create and install a documentation set for your classes, all Quick Help displays is a link to the header file where you declared the class, method, or data member.
Appledoc seems to be your best option. I know it's not the answer you're looking for, but it doesn't seem too bad.

Related

Dynamically Mocking iOS Dynamic Type System Text Size (UIContentSizeCategory)

I'd like to easily test my app with different selections of system text size, including accessibility sizes. These can be set in the Settings app (Display & Brightness => Text Size or General => Accessibility => Larger Text).
The only way I can find to currently do this is to go into Settings and change the value with the UI (edit: partial solution described below). This is slow and cumbersome. I suspect there's a way to dynamically alter it using private APIs, but I can't figure out how. Since my goal is to only use this for debugging, private API use and swizzling is fine (this code won't be making its way to production).
To try to find a private API to do this, I looked at some reverse engineering resources. I'm new to disassemblers, symbol tables, class dumps, and finding private APIs I can use, but this is what I've tried so far:
I successfully swizzled -[UIApplication preferredContentSizeCategory] (other posts said this worked in the past), but this doesn't affect the result returned from +[UIFont preferredFontForTextStyle:].
Using the disassembler IDA I discovered that +[UIFont preferredFontForTextStyle:] is in the private framework UIFoundation.framework. (-[UIApplication preferredContentSizeCategory] is in UIKit.framework but the disassembly didn't look at all useful).
Just as I started writing this question (it always happens that way), I discovered a partial solution. One can set a launch argument in the scheme to set the value on launch. This is useful, but not what I'm after.
Through the above answer, I found the value for the user's preference is apparently stored in "the com.apple.UIKit.plist file located in the Simulator's data/Library/Preferences directory". The value we're after can be set from the command line utility plutil. This is also an improvement! But I'd like to dynamically alter it at runtime.
More on my results from IDA:
I don't really know how to read disassembly, but +[UIFont preferredFontForTextStyle:] seems to point to a symbol called ___UIFontForTextStyle which seems to point to some interesting-sounding symbols called _getUIContentSizeCategoryUnspecified and _getUIContentSizeCategoryPreferenceClass
I also found these symbols using the command-line utility nm on UIFoundation.framework. They were marked with the lowercase letter "s" meaning, apparently, "The symbol is in an uninitialized data section for small objects.". I have no idea what this means (all I've gathered is that they're not a class or method).
Searching the web for the _getUIContentSizeCategory... symbols yields nothing, but nearby there's another symbol _getUIApplicationClass. I searched for that one since it sounded a bit more general, and found something similar in some WebKit source. Could be nothing, but maybe it's an internal Apple convention. Regardless, the example doesn't really help me solve the problem.
Anyway thanks for reading so far. If you're still here, my question is:
I'd like to be able to dynamically mock the value for the dynamic type size preference. These disassembly symbols might help, but maybe I'm on the wrong track. It feels like the solution is close but I just can't put all the pieces together.
Setting this value as a launch argument is nice, but doesn't fully solve my problem. Similarly, modifying the Simulator's value in the plist is also nice for automation, but doesn't solve my problem.
Is there a way to dynamically alter this value at runtime?
How embarrassing! I was looking at some out-of-date iOS 9.x documentation and missed that UITraitCollection gained init(preferredContentSizeCategory: UIContentSizeCategory) and var preferredContentSizeCategory: UIContentSizeCategory in iOS 10, which was helpfully pointed out to me by Brandon Williams. This addresses my needs perfectly.
One easy way is to write a wrapper around UIFontMetrics and route all UIContentSizeCategoryDidChange notifications through that. It allows for unit/UI testing various Dynamic Type settings. I wrote about it here.

Is there any easiest way to implement all required methods of protocol in iOS?

First of all it's not the duplicate of this question because i couldn't find any discussion about offline documentation, suitable answers and about future release of updates in Xcode there.
Actually I am from android and java background and currently starting to develop iOS apps too. As we all know we use to implement all methods of an Interface easily with the help of suggestions given in IDE by pressing Alt + Enter.
And here in the iOS we have to see the reference each time and search for all required & optional methods, and implement them manually one by one which consumes times It's fine for a moment But
My Questions are :
Is there Any easiest way to view all required method at first lookup in documentation OR implement all required methods of protocol with the help of IDE ?
Is it possible that we will get this feature in future release of Xcode's update ?
I can't be ensure availability of Internet all the time, And How can I see the documentation at that time ?
Just go ahead and declare that your class adopts the protocol in question.
Xcode will point the error if you fail to implement any of the required methods:
From the list under the disclosure triangle (items with gray "!" icons), you can get a hint of the names of the missing methods. You can start to type and autocomplete will do the rest.
Update for Xcode 9:
It looks like now, you can auto-fill the methods with one click:
Refactoring
Rename a symbol in a single file or in a project across Swift, C, Objective-C, C++ files, and Interface Builder files.
View all the possible changes in one editor pane.
Convert method signatures between Swift and Objective-C formats.
Update properties, getters, setters, and synthesized iVars as needed.
Apply a fix-it everywhere with one button.
Automatically fill in missing cases in switch statements, and mandatory methods for protocol conformance with one click.
Extract method functionality for all supported languages, along with other language-specific local refactoring.
(emphasis mine)
And indeed:
Clicking "Fix" adds the necessary method stubs.
Go to Xcode -> preferences(on top-left corner) -> downloads -> here you will see list of items that can be downloaded. Download the documentation for iOS x.x version. So now, whenever you are offline.. you can go to help(top bar in window) -> documentation and search for whole ios documentation.. all the development guides etc

How to find unused properties for iOS class?

I cannot find any similar questions on this topic, which seems strange..
I have what is turning out to be a rather large project. As I build each chunk, I'm aware that I must be making properties and other resources, that do not end up being used.
Is there a way to find these?
Good question. I always need this too in my projects. What I do is either use search for .property or setProperty etc. in the whole project.
Or I traverse the .h files and comment out the property declarations that I suspect I might not be using and hit Command+b and see if it gives any errors.
I hope there is a function/tool specifically built for this need.

Add warning dynamically to Xcode Project

I am asking my self if there are a way to add dynamic warning to my project.For exemple, every method in my class should begin by an analytics tag (setTagVorView:), if this line doesn't exists, I or other developers will be notified by a warning on this method.
Today, my only solution is to create a protocol (delegate) with a required method and every class (UIViewController for example) should follow this protocol and implements the required methods. The problem is : if the developer forgot the delegate, he will never be notified.
Another example, the appledoc command line tool add warnings to the project if some properties or methods don't have descriptions.
So how can i add my rules to predict warnings in some cases ?
Thank you.
Not sure if it fits your needs, but there is at least on way, hardcode way to achieve this goal: create a clang plugin and add there your own rules.
I'm not going very deep, because it might take too much time, but if you really interested in this solutions you can take a look at this blog-post, there is actually described a way to make the plugin with custom warnings and even errors
You could use NSAsserts in all the methods you want the developers to override:
NSAssert(NO, #"You need to implement this methode!");
It's, of course, not as elegant as compile time warnings.
Alternatively, you could create a XCode file template,with hardcoded warnings in. Take a look at this SO answer

What is the XNA 4.0 equivalent of GraphicsDevice.CheckDepthStencilMatch?

I've been trying to work through a tutorial which I foresee will be very helpful to my current project, but it was target at XNA 3.1. Thus, many sections of code (which the author does not explain too much) are now obsolete. Here's a pastebin of the file. The main thing that sticks out to me is the GraphicsDevice.CheckDepthStencilMatch function. I can't seem to find out much about it. Is it even necessary anymore? As you can see I've commented out some of the sections which I think are no longer required.
Check out XNA 4.0 method: GraphicsAdapter.QueryRenderTargetFormat Method
The description for it:
Queries the adapter for support for the requested render target
format.
I believe this is what you're looking for.
Let me know if you need specific code sample or anything else.

Resources