I am having trouble getting Xcode 8 with Swift 3 to auto-complete common initialization methods, and was wondering if there is anything I could do to fix the situation.
Specifically, take something like:
let jsonString = String(data: jsonData, encoding: .utf8)
The initialization method String(data:, encoding:) will not populate.
Demo Video
I find it useful to type the actual word .init before asking for code completion. Then later, I take it back out again.
Note that Xcode is very choosy; if you go too far and type .init( it won't work.
EDIT According to Apple, this problem is fixed in Xcode 10.
Related
I was able to install the vim-go plugin and configure my vim pretty much as shown in the tutorials for golang development. There is one thing though that didn't work for me, I am not sure if it was intended that way but it's pretty annoying for me and I would like to know if there is a way to fix it.
The problem is that the syntax highlighting doesn't work consistently when it comes to custom types as for the type list []int as seen in this screenshot Ideally, the type should be highlighted for both these lines
func removeDuplicates(ld list) list { // <- here
var lu list // <- here
this has been driving me crazy, please suggest something. Surprisingly in main it does highlight where the variable of the same type is provided with initial values.
When building my project in Xcode 8 GM, Xcode sticks on "Compiling Swift source files". It also never finishes indexing my project at any point.
I've looked at the similar questions but none of those answers work for me.
Does anyone know what this could be?
Swift inference was the problem.
There were several instance where I was inferring a dictionary type that for some reason grew exponentially as the dictionary had more values.
If you used lot of Concatination of string like
var fun=0;
var tempvalue=2;
var result="some data"+fun+" more data"+tempvalue;
Transform it to
var result="somedata \(fun) more data \(tempvalue)";
Because swift compiler take lots of time to analyse overloding methods of "+" operator
Clean Build Folder (Cmd+Shift+Opt+K) usually helps me in this case, but time to time issue returns.
I've just gone back to a project I started ages ago and the compiler is throwing out hundreds of errors about objects not being convertible (to objects which subclass them), and suggesting I use as! instead of as, to force the cast.
Is this a bug in the latest X-Code beta, or has the down-casting syntax changed?
The syntax has changed for Swift 1.2. See Apple's blog post about it.
Here's a summary from their article:
Swift 1.2 separates the notions of guaranteed conversion and forced
conversion into two distinct operators. Guaranteed conversion is still
performed with the as operator, but forced conversion now uses the as!
operator. The ! is meant to indicate that the conversion may fail.
This way, you know at a glance which conversions may cause the program
to crash.
I think several people has experience this problem, and that's with enums.
So the problem is quite simple, Xcode handles indentation after enums quite strange, at first I thought it was my syntax, but it turns out that it's probably not (I'm not ruling that out just yet)
So here's what my code look like:
enum Signs : bool {
Positive = true,
Negative = false
};
<This is where Xcode suggest where my next line of code should be, which is one tab more then I expect.>
Anyone seen this problem and solved it?
This bug can be replicated 100% of the time by specifying a value for one of the enum members.
If you omit the = true, automatic indentation will perform correctly. This goes for any enum with any number of enum items. As long as one item has = someValue, the closing brace will be misaligned.
it's 2018 and the developers of XCode still haven't fixed this bug in Xcode 9.2. So, please file bug reports (Help menu -> Report an Issue), now that the method for reproducing it every time has been discovered.
I usually write my enums like this:
//Using your example
typedef enum {
kPositive,
kNegative
}signs;
There you won't have the indentation problem. But I can't answer why Xcode behaves like that.
Is it possible to see strings that use 16 bits chars in Xcode debugger? I use a custom string class, not NSString. The strings are NULL terminated. The only way I can see the strings is if I see them as memory, but they are hard to read.
Thank you!
You'll need to write a data formatter bundle -- just writing the data formatter expressions inside the debugger isn't enough. Viewing strings in the Xcode debugger is a black art. Even once you've written the data formatter bundle, be prepared for them not to work at least 50% of the time. We've been fighting this issue for about 5 years now. Most of the time the debugger will tell you the variable is no longer in scope when it really is, and you'll still need to drill down into the members to view the raw memory anyway.
Something that may make it easier (I haven't tried this) is to write a method in the class that returns an NSString and then you may be able to get the data formatter expressions to display something useful.
Use Data Formatting in the XCode debugger
For custom classes I always found it helpful to implement description and debugDescription methods. Maybe this approach will be sufficient in your case too.