Add warning dynamically to Xcode Project - ios

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

Related

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.

Confusion about objc_getClass

In my Xcode project,I added the same framework for ios7 and ios8.I have renamed them to xxx-ios7.framework and xxx-ios8.framework.
I want to use objc_getClass("someclass") to get the runtime class.But the two frameworks have the same class.
How shoud I know which class I will get?
Although this may not be a great answer, you may want to use the same mechanism that Microsoft used in their MFC classes, which is defining a version number.
In essence, you would have a method, or methods like:
- (NSString*)classVersionAsString;
- (NSInterger)classVersionAsNumber;
which would return meaningful version information for you.
As noted in the comment above, you should be careful with having multiple frameworks with the same class names, since, the loader will pick the first class that matches a linker requirement by the dependent module or dependent application. When the modules are loaded, the class you get might not be what you expected.

Customizable UISwitch that is ios5 (ARC) compatible

I need to use a custom "knob" image on a UISwitch. I don't think this is possible with the default SDK. Does anyone know how I might go about this or of any 3rd party libraries that can do this? I've found a few but they are all old and don't work with ARC.
Generally to do something like this you would subclass UIControl. I'm sure there are a bunch of implementations of this particular control type floating around. I found one that you can use here. There is a github link on the page.
By the way, if you find a class you want to use that is not arc enabled, you can either try to convert it yourself (although this will make it harder to download updates for it), or more commonly add the -fno-objc-arc compiler flag to whatever files are not arc compatible and it will exclude them (but you can still use them). More info on that here.

Comments style for xCode

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.

Resources