How can I Quick Look custom objects with Xcode 5 visual debugger? - ios

Xcode 5 has a great new feature where you can hover over a variable name and get a visual representation of a UIColor, UIImage, or even UIBezierPath.
I vaguely remember a comment at WWDC where developers could either conform to some protocol or override some methods on any NSObject subclass in order to participate in this new debugging feature. I would love to add this to a bunch of my model objects to help me debug. Anyone know whether this is a real thing yet, or even if they hinted at it in a future release?
Unfortunately, Apple refers to this feature as "Quick Look" and since they have another technology called "Quick Look" my search results are very noisy and I can't find anything helpful.

This is a new feature in Xcode 5.1, and the documentation on it can be found here. In a nutshell, you override -(id)debugQuickLookObject and return an OS type that already supports Quick Look, e.g. UIImage or NSAttributedString (full list of types in documentation):
- (id)debugQuickLookObject
{
UIImage *image = [...];
// Drawing code here
return image;
}
For Swift:
There are a few options as of writing, none ideal:
Conform to CustomPlaygroundQuickLookable, but that only works in Playgrounds (and requires Xcode 7/Swift 2).
Use the same method as for Objective C. This requires your class to be marked #objc (or inherit a Objective-C class) as the caller relies on selectors.
Conform to Reflectable, but that requires you to provide a full custom MirrorType with a bunch of other properties along with the QuickLookObject (and doesn't even seem to work as of Xcode 7?)

Now that 5.1 has been officially released I've released this new blog post on the matter.
To answer your question: Yes, this is indeed a feature available in the new release of XCode (v5.1) and can be used very easily by subclassing an object and returning whatever it is you want to see while debugging in a -(id)debugQuickLookObject method.

Related

How to wrap existing iOS code in a new Appcelerator module?

This seems like a basic request, but I can't find the answer to it anywhere. I want to wrap some existing iOS code that I wrote, in a Appcelerator module. That's it. Important points:
I am NOT wrapping a pre-existing 3rd party iOS SDK.
I wrote the iOS code being wrapped.
Code is verified as working within xcode.
There are no .a files. There are 2x .h files and 2x .m files though.
There are no UI elements in the iOS code as it is only designed to connect the native bluetooth hardware to the app.
I have created a generic appcelerator iOS module project, built it, and successfully called the generic ID function within my app.
I cannot figure out how to successfully edit the generic module so that it utilizes my code. Every attempt results in it refusing to compile, and it's maddening.
I do not have access to Hyperloop.
Once I can successfully build the wrapped module, I would call an initialization function which triggers a native bluetooth hardware search. Once connected, there are functions within the module to send commands to the hardware and receive data back. This is the official documentation I've followed so far:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Quick_Start
That helped me build the blank module, include it in the app, and ensure that it worked by calling the built in test property. From there it stops short of actually telling me what I need to know. These are the closest things I've found so far, while still not being what I need:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Project-section-43288810_iOSModuleProject-AddaThird-PartyFramework
appcelerator module for existing ios project sdk
Heck, I still don't even know if I can do this within studio or if I have to edit the generic module in Xcode. Help! :) Many thanks in advance.
so first of all, this is not best practice and will cause possible problems in the future when the SDK changes and your module still relies on outdated core API's.
Regarding your question, you could either create a new component that subclasses the existing class, e.g.
class TiMyModuleListViewProxy : TiUiListViewProxy {
}
and call it with
var myList = MyModule.createListView();
or you write a category to extend the existing API with your own logic, e.g.
#interface TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value;
#end
#implementation TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value
{
// Set the value of "somethingElse" now
}
#end
I would prefer the second option since it matches a better Objective-C code-style, but please still be aware of the possible core-changes that might effect your implementation in the feature. Thanks!

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

Auto-implement Swift protocol methods in Xcode

I just started with the swift language and coming from java it looks great so far.
But I'm really missing something:
Eclipse had this great feature that when I added "implements XYZ" it provided me a function to automatically implement the necessary function stubs. This is a huge timesaver.
Xcode doesn't seem to have this feature, or am I missing something?
I found the accessorize plugin, but this seems only to work with Objective C..
Is there a solution?
PS. I'm using Xcode 6.1.1
NB: This answer is true for Xcode before version 9; in Version 9 Apple added the ability to automatically fix up missing protocol methods; see Guy Daher's answer.
I just created an iOS project, and headed into my UIViewController.swift file. There I declared that it implemented UITableViewDelegate:
class ViewController: UIViewController, UITableViewDelegate {
Now when I go into the body of the class, and start typing "tab...", I see the appropriate autocompletions:
Hitting Enter then inserts the function stub, with the cursor placed ready to code.
That's just the way Xcode autocompletes protocols (or inherited class methods.) If you want to do all of them at once, I don't think it's possible, sadly. But you can always Cmd-click or Option-Cmd-click (which uses a secondary editor window) on the protocol name to jump to its definition, which is basically a list of all its methods you can copy and paste into your code. You'd need to tidy up a little from there, but not much.
Xcode 9
Xcode 9 now supports conforming to protocol methods via a "fix it". It will automatically fill the missing methods for you. This was announced in WWDC 2017.
Update: This doesn't seem to work for protocols defined by you, unfortunately.
Xcode 9, takes care of implementation of mandatory methods of Swift Datasource & Delegates.
Look at these snapshots, with example of UICollectionViewDataSource:
Indicating warning to implement protocol methods:
By clicking on 'Fix' button, it has added all mandatory methods:
Alternate Option:
You can use a keyboard short key: Ctrl + Option + Command + F to fix all issues at once.

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.

Is IOS 5 UIDocument subclass backwards compatible?

To support iCloud, we're encouraged to use a UIDocument subclass. If I define a new subclass, set the project target version to 3.0, and test using for iOS 5 before using my new subclass, will the code work on iOS 4 or does linking in a subclass break backwards compatibility?
UIKit can be weak-linked, but the results would be undefined if you tried to initialize a UIDocument or UIDocument subclass. You would need something like:
if (NSStringFromClass(#"UIDocument"))
{
...
}
That would make it totally useless for your purposes. So the answer to your question is no, any code involving UIDocument would not run, but you could put conditional checks around such code. You're better off finding an alternative method for saving data.
It will need to link with UIDocument in order to understand what subclassing UIDocument actually means. For example, if you have class Bar which subclasses Foo, and Foo has method 'doBaz', you can call 'doBaz' on a Bar instance, but if the linker doesn't know Foo, it doesn't know Bar can doBaz.
You may be able to do a weak link though. There was a similar situation when iOS 4 came out, with iAds not being available in iOS 3, which was the best on iPad at the time.

Resources