Xcode code completion missing variables & methods? - ios

I was following along with this tutorial, and was very confused when I tried to access:
UINavigationBar.appearance().barTintColor
The reason I was confused is because Xcode doesn't show "barTintColor" as part of it's code completion.
Instead, it offers me "tintColor" and "backgroundColor", both of which do not work like the tutorial. However, when I manually type in "barTintColor" it works correctly.
Why would "barTintColor" not show up as part of my code completion? And is there something I can do to avoid similar confusion in the future?

If I had to guess, you're experiencing behavior because barTintColor is a property of a UINavigationBar, and not a property on the UIApperance protocol. Code completion must be trying to get the possible methods on the internal _UIAppearance.Type (the type of appearance()) rather than the UINavigationBar class.

Related

Disable Xcode 8 code completion for image name

Is there any way to disable code completion hints for image name in Xcode 8?
According to the manual you can't select what the code completion shows and not, since the code completion shows all the assets that it has to the apps disposal in its surrounding context. If xcode thinks it should first provide you with images from the asset catalogue, it will unfortunately do so.
You can turn the code completion of in the text editing preferences or you can toggle the code completion on and off when typing with Control-Space bar and you can dismiss the code completion with the Escape key. If you turned the code completion off in the text editing preferences you can still turn them on with Control-Space bar.
I created a snippet with the completion shortcut "in" that replaces itself with "in" to stop it from suggesting images when I'm trying to write a Swift closure. If you have other annoying use cases perhaps further snippets might help.
I've found a temporary solution by installing this plugin.
https://github.com/keith/IgnoreXcodeImageCompletions

KVC in UITableView subclass causing crash with accessibility enabled

I have a custom UITableView subclass in which I override +accessInstanceVariablesDirectly to return NO in order to ensure attributes with no setter cannot be set using KVC.
When removing this table view from the view hierarchy, the app crashes - sometimes - and now for the weird part: only if Accessibility is enabled! (i.e. the Accessibility Inspector is visible, or you have Accessibility enabled on a physical device)
If I do not override +accessInstanceVariablesDirectly, everything works fine. I figured maybe UITableView relies on accessing some instance variables directly - but then what is the point of this method, if I can break superclasses by using it? Is there a way to specify this behavior per-attribute, like +automaticallyNotifiesObserversForKey:? However I am baffled by the fact that this issue only exists when Accessibility is enabled.
I tried analyzing the project with various Instruments, but without success.
You can find a minimal project reproducing the issue here. I would greatly appreciate any pointers on why this is happening or how to achieve what I want nonetheless.
This issue appears to be fixed in iOS 9.

Rendering UIView in Swift with #IBDesignable, crash

I have a graph built in Paintcode that I am showing in a UIView. It works fine in the App but will not render in storyboard. I have read a host of different posts about overriding init frame, and init coder. However, I can't find a specific example that helps me with my problem, by showing the practical use of these overrides.
The graph takes 14 variables to produce a bar chart. Here is the class code
import UIKit
#IBDesignable
class graphRisk: UIView {
override func drawRect(rect: CGRect) {
StyleKitGraph.drawRiskGraph(ehsScale: ehsScale, ciScale: ciScale, stratScale: stratScale, qaScale: qaScale, delScale: delScale, leadScale: leadScale, peopScale: peopScale, hrmScale: hrmScale, pmScale: pmScale, costScale: costScale, finScale: finScale, assScale: assScale, itsScale: itsScale, engScale: engScale)
}
}
It looks good in the App, and it is no big deal if it doesn't render as the variables are coded, and the design is fine, however, I removed the #IBDesignable tag and it still errors the same.
Finally, how do I get the UIView to update when I enter the view controller it resided in?
So the questions are;
1 How do I get render to work for this code example?
2 Is there a way to not render the view, and stop the error that way?
3 Do I need to worry about the error as the App runs fine?
4 How do I get the UIView to refresh. What is the syntax for .setNeedsDisplay() etc? I tried lots of things and none updated or reloaded or refreshed.
As always I truly welcome all help, and thank you.
Not sure what version of Xcode you are using. I am using Xcode 6.4.
I, like you, have researched for days on many websites and tried many solutions. None of them worked. At last, I removed the #IBDesignable to my custom UI class. Not only did the error went away, the instance of the custom UI class previewed fine in Main.storyboard.
Perhaps, in the new development of Xcode, #IBDesignable is no longer necessary.

Adding array of UIImage in a UIViewController with some alignment

I just started my first project in iOS, recently I have encountered a problem in the UI when i receive it from the designer.
The expected output is shown as below and i can do most of it without any problem.
Now the problem came when I am about to implement this :
As the number of colour varies depending on item, I cannot add it like what I did for the share and love button I have no idea how can i implement something like this, I have look through the Object Library in the storyboard and cannot find any that can produce the output as expected .Any helps and guides are much apprecited!

When is -[UITextInput selectionRectsForRange:] called?

I have an app with a custom text editor that implements the UITextInput protocol. In iOS 6, Apple added one new required method to the protocol:
- (NSArray *)selectionRectsForRange:(UITextRange *)range
I've implemented this, but I can't seem to find a way to trigger it. At least in the way my app works, it seems to never get called by the text system. Does anyone know what it's used for?
This method is only used by subclasses of UITextView. This is the only method that would give you the system selection and loupe. This is what I was told at WWDC.
I am working on my own DTRichTextEditor as well and I implemented it nevertheless, maybe one day we get the selection/loupes also for our own UIViews that are not derived from UITextView.

Resources