Xcode 8.2.1 not showing documentation description on autocomplete - swift

I'm having problems adding documentation to my code in Xcode 8.2.1.
Here's my code:
/// Test documentation method
///
/// - Parameter string: The input string
/// - Returns: The output bool
func testMethod(string:String) -> Bool {
if string == "YES" {
return true
}
return false
}
The documentation shows as expected in the quick help window but the description doesn't show in the code autocomplete window.
Is there a way to get the description to show in the autocomplete box as in the image below:

You are right, the descriptions you added to the top of your methods and properties don't appear in the popover anymore.
As noted, you can only see the descriptions of Apple's own methods and properties.
The reason being that Xcode doesn't parse these from their classes but rather from a separate documentation set (which you can find in Xcode's Help/Documentation and API reference tab).
So unless Apple decides to change this, I'm afraid it won't be possible to see your own in the popover.
You could keep an eye on existing doc set generators (AppleDoc, Jazzy), maybe they'll offer a way to link their documentation to Xcode's popover.
Keep in mind that you do see your own comments when opening the quick help popover with alt + click on a method or property.

For me the best way to resolve this is by cleaning the project Shift+Command+K, and if that is not working, it is a god idea to remove Derived Data folder.
To remove this folder go to Xcode preferences, Locations tab
and click on the small arrow to open a finder, and remove manually the folder.
Restart Xcode, and check if now is working

https://developer.apple.com/library/content/documentation/Xcode/Reference/xcode_markup_formatting_ref/MarkupFunctionality.html#//apple_ref/doc/uid/TP40016497-CH54-SW1
please refer the official documentation

Related

Xcode Storyboard not updating custom class Designables

I have had many problems after closing Xcode which one of them is that Xcode Storyboard is not updating Custom Class Designables anymore and do not show the content. For example I use "SkyFloatingLabelTextField" which worked perfeclty before so I can't blame the library. Is there some way so I can force it to update it?
What I mean illustration:
As you can see, in the first picture I have assigned the custom class and there is actually textField inside my viewController which for some reason doesn't show up anymore in Storyboard but works on real device or simulator.
So can I force it somehow?
I tried removing the class and all runtime values, clean, build close Xcode but nothing is working.
Huhh... Enabling "Automatically refresh views" did the trick. For some reason it was turned off in my case. If you do not know what I mean, then it is the setting in Editor -> Automatically refresh views

WatchKit Extension[4608:145616] Unable to find image named "hello" on Watch

Problem:
Trying to set the WKInterfaceLabel text using xCode 6.2 but it returns this error:
WatchKit Extension[4608:145616] Unable to find image named "hello" on Watch
Code:
#IBOutlet var lblPassword: WKInterfaceLabel!
lblPassword.setText("hello")
Cleaning the project doesn't seem to fix the issue for me. But if you click on the image file, you'll see "Target Membership" options on the right pane. Select all of them, Clean the build and try again.
I got the same error although I am pretty sure these image files exist.
I just terminated Xcode, relaunched it, cleaned the project (command + K) and built it. It started to work again.
I do this routine whenever I face a new problem. It solves most of the problems as you might know. Sorry if you have done it already.
I supposed that you adding image to asset catalog in WatchKit Extension. This is wrong.You should add that image to asset catalog in WatchKit App. Sorry i can't add image here.
Try as I might, my images were not loaded up to the watch until I did it directly by 'caching' as follows in my InterfaceController in the WatchKit Extension:
[[WKInterfaceDevice currentDevice] addCachedImage:[UIImage imageNamed:#"carrota.png"] name:#"carrot"];
[self.portfiolioImage setImageNamed:#"carrot"];
For me, it looks like you have added "hello" as an image name somewhere in the storyboard.
Use XCode's Find dialog to look for "hello". It will show use as an image name, too.
Screen Shot 1
Ok So the keything to note here is that "you do not want to drag and drop the images into the AssetCatalog"......the only way this worked for me was to manually right click on the catalog (as shown in screen shot 1 and "Add Files"....look for the image you want to add on your local/external drive (Making Sure that only the "WatchKit App" Checkmark is selected in the Add to Targets Section" as shown in Screen Shot 2) and add the images!!
Screen Shot 2
i've had the exact same problem. solution: i've exedently connected the group parenting the WKInterfaceLabel. Try setting YOURSUPPOSEDLABLE.setTextColor(.brown), if the Background of it changes, you have connected the group.
So in my case I had copied and pasted a prior row and assigned a diff class.
That duplicated row's group still had an IBOutlet connection to the prior class that I did not catch.
Once I removed that connection this stupid issue resolved itself and I was able to successfully call .setText()

How to check if any apps are associated with file extension

I want to make "Open in.." function in my iOS application.
Is there any way to check if any app on this device is associated with file extension that i want to share?
If there are no apps on current device to open file with such an extension than UIDocumentInteractionController will not be displayed after clicking on "Open in.." button, but i want not to show this button in such case.
So the question is: how to check if any app on device can open some file with specific extension?
Update:
For example UIDocumentInteractionController has NSArray property icons.
It contains images of all aplications that can open the file with my extension. But if there are no applications it contans image of empty application.
So i can't check it using docInteractionController.icons.count == 0 for example. I am looking for other tricks.'
Thanks, in advance.
Although UIDocumentInteractionController does not offer a way to discover in advance whether there are any applications that can handle a document, -presentOpenInMenuFromRect: will return a flag indicating whether there were any applications that could open a document. This requires you to have already set up and presented the controller, which is not optimal.
There is a workaround for this, a little hacky but is functional: Before you invoke the "real" interaction controller, create a dummy one using a dummy document, and present it from the rect of the window's bounds. This guarantees that it will "appear" offscreen, so your user won't see it. At that point, you have the flag returned from -present, and you can immediately dismiss the dummy controller, and the proceed to show your UI appropriately.
On OSX, you can get a list of application bundle identifiers capable of handling a specific content type using LSCopyAllRoleHandlersForContentType. But on iOS, I don't think there is such a way.
If I find, I'll edit my answer.
Considering you are looking for other tricks, you can check if that one image in the icons array is the generic document icon.
If it is then you know that there is no app associated to handle that file type. But this approach will be OS version dependent as generic file icon may change.
From the official documentation:
To declare its support for file types, your app must include the
CFBundleDocumentTypes key in its Info.plistproperty list file. (See
“Core Foundation Keys”.) The system adds this information to a
registry that other apps can access through a document interaction
controller.
To me this indicates that the registry can only be accessed through UIDocumentInteractionController and so no, you would not be able to know in advance if there are any available apps for the file format (which would be totally in line with Apple's philosophy of not letting apps interact directly with each other).
UPDATE:
as you said the icons property contains an image even with no applications present. I checked and all the other methods and properties of the controller do not give an hint about the apps that may open the current file format.
You said in case that no app can open the specified file format there is an "image of empty application". Maybe you can extract that icon and when the array icons only has one image check if the extracted image and the icon are the same?

Xcode 4.2 is missing a .xib file?

So I'm pretty new to programming, so I downloaded Xcode 4.2 and got to work. I watched many online tutorials and the main problem I was having was that all the tutorials were for Xcode 4 and not 4.2, meaning when you chose empty application setting, it was missing the .xib file. So I found a tutorial on how to create a .xib file. I got through it all except for one step, and that was to drag the from the window outlet of the xAppdelegate to the window. I've tried this over and over, but it doesn't work.
Here is the tutorial if anyone needs to see it http://www.trappers.tk/site/2011/06/16/mainwindow-xib/
Please someone help me!
You need to hold Ctrl while dragging, else it will not work.
Guide.
As you Control-drag from an object to your source code, Interface Builder indicates where a new binding is valid. After you’ve made the connection, Xcode displays a dialog you use to configure the binding. You can use the dialog to configure all aspects of the binding.
Interface Builder uses the Xcode index to determine which key paths are valid, and can also discover what controller it should connect through—you can therefore connect from a user interface element such as a table column to a property in a model class header.
Check out the video here.
You should choose a SingleViewBased Application instead of Empty Application then study all files that how they connect with each other. You can choose Master Application also. They will help you.
see this Hello world Tutorial click me.
And Youtube is the best way to learning for beginners. Search tutorial video because action teach more than the text.

Change language in app - how to restart?

I want to give the user the possibility to change the language in my app.
The way to do this is described here, in monotouch code to set the preferred language to Dutch and alternate language to English:
NSUserDefaults.StandardUserDefaults.SetValueForKey
(NSArray.FromStrings("nl", "en"), new NSString("AppleLanguages"));
You have to restart the application before this will take effect. But on the iPhone 4 the app does not restart when you close it, it is just hidden. Is there a way to force an app to restart after closing?
Thanks Dimitris. So changing the language at runtime is not that simple.
I found a solution which works in my case:
When the user changes the language I use the solution described by Mauro Delrio in "How to force NSLocalizedString to use a specific language". In monotouch:
string newLanguage = "nl";
myBundle = NSBundle.FromPath(NSBundle.MainBundle.PathForResource(newLanguage, "lproj"));
All strings will now be loaded in the selected language with myBundle.LocalizedString(...). Of course, everything which was already printed on a view is not yet translated. But I found an easy way to reset all views. In my app I use a MainTabController which looks like this:
public class MainTabBarController : UITabBarController
{
public override void ViewDidLoad()
{
Reset();
SelectedIndex = 2;
}
public void Reset()
{
ViewControllers = new UIViewController[]
{
new ViewControllerTab1(),
new ViewControllerTab2(),
new ViewControllerTab3(),
new ViewControllerTab4(),
new ViewControllerTab5()
};
}
}
So all I have to do is call Reset like:
((AppDelegate)UIApplication.SharedApplication.Delegate).MainTabBarController.Reset();
All current views are disposed and re-created in the correct language. Seems like a trick, but it is perfectly legal and documented, see Apple documentation for MainTabBarController viewControllers property. It even activates the same tab index as the one which was active, so for the user it seems that nothing but the language is changed.
Of course, any unsaved data in all views is lost, so if this is a problem, you have to find a way to save this before resetting.
No there is no way to restart an app. You can only force it to terminate when the users presses the home button by setting the property "UIApplicationExitsOnSuspend" in your Info.plist file to true.
The trick to use specific language by selecting it from the app is to force the NSLocalizedString to use specific bundle depending on the selected language ,
here is the post i have written for this http://learning-ios.blogspot.com/2011/04/advance-localization-in-ios-apps.html
and here is the code of one sample app https://github.com/object2dot0/Advance-Localization-in-ios-apps
As an additional note, to force the UIBarButtonSystemItem to change their locale, you have to add
<key>CFBundleDevelopmentRegion</key>
<string>nl</string>
to your info.plist. Just fire up TextEdit and place it somewhere. Hope this helps!