Swift code completion isn't working - xcode

I installed Xcode 6.0 beta and downloaded the iOS8 library Documentation.
but when i create a Swift project, try to typing code
func aa(){
let format = NSDateFormatter()
var pageData = format.
}
I find Xcode can't dot any property and function. Am I missing any step?
The problem is sloved, typing a whitespace can aid code completion

It's append when you change the hardware type and you choose less than iphone5.
Choose Iphone 6 for example in the list at the right of the stop button and the code completion for 'format' will appear.

I met the same problem and solve it by removing the non-ASCII char in comment (in my problem, it's a chinese char "年" automatically generated in comment by xcode).
btw. "typing a whitespace can aid code completion" doesn't work for me

It’s a bug, your code works on my system (OS X 10.9). Note that when typing code, I sometimes see the code completion crash for two seconds and come back.
When trying a first project named "swift", code completion crashed in a infinite loop… beta bugs… I just had to name it something else to test the language.

You know, I've experienced something similar with Objective C projects in Xcode 6 Beta 1. It seems Apple have changed the default behaviour a bit:
In Xcode 5.x code would always automatically complete as you type, but in this early beta try pressing ESCAPE - that will bring up the list you're looking for. Works for me. Some code auto completes as you type (both in Swift and Objective C), but at times only ESCAPE will bring up what we're looking for.
I'm nor sure if this is expected behaviour or a bug (I'm guessing the latter).
I must admit that your code works fine on my system without this trick. Just make sure you have code completion setup under Xcode - Preferences - Text Editing:

Related

Class PLBuildVersion is implemented in both frameworks

iOS 10 / Xcode 8 GM build getting the below, never had it before on Xcode 7. Any ideas?
objc[25161]: Class PLBuildVersion is implemented in both
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices
(0x12049a910) and
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices
(0x1202c4210). One of the two will be used. Which one is undefined.
(NOTE: Only seems to happen in simulator, does not appear on real device).
Main Idea
Main idea is simple:
If your app (or dependencies, such as Pods) uses framework, that uses explicit (or implicit) PhotoLibraryServices.framework or AssetsLibraryServices.framework as dependency, Xcode warns you (even if you are using only one of them). It might be Photos/PhotosUI.framework or AssetsLibrary.framework, or another (I don't have full list of dependencies, but it is possible).
What is the problem?
Class with name PLBuildVersion is defined in both PhotoLibraryServices.framework and AssetsLibraryServices.framework. Class name is unique in Objective-C (you can't define 2 classes with same name), so it is undefined which one will be used in runtime.
However, I think that it will not be a problem, because both classes have same methods and fields (checked this with disassembler) and I guess that both were compiled from the same source.
Radar is already sent.
As per answer from Apple employee on Apple's Developer Forum:
You don't control either of the class sources listed, so there isn't anything you can or should do – aside from Reporting a Bug.
I was unable to find a way to get rid of the warning, but if you want to prevent the app from crashing, you need to provide a description for why you are accessing the camera, photo library, etc. This is new in iOS10.
Input the following into your Info.plist file.
Photo
Key: Privacy - Photo Library Usage Description
Value: $(PRODUCT_NAME) photo use
Camera
Key: Privacy - Camera Usage Description
Value: $(PRODUCT_NAME) camera use
More info can be found here: https://iosdevcenters.blogspot.com/2016/09/infoplist-privacy-settings-in-ios-10.html
I find you can get this error merely by using a UIWebView. My solution was to replace my use of UIWebView with WKWebView.
I had this after adding Answers on Fabric to my project.
Deleting derived data did the trick for me. (shift alt command k in XCode)
Edit a year later:
After deleting derived data, always exit XCode and start it again.
In unrelated cases I have the impression that deleting derived data does not clear XCode’s in memory caches of the derived data.
Resetting the iOS simulator fixed this for me. Simulator -> Reset Content And Settings.
In my case this warning started to appear after opening a second xcode project and running the second app on the simulator. After changing back to the first app, the warning started to appear. I just quit the Simulator and Xcode and reopened my project. The warning disappeared after that. If that doesn't solve it, proceed with the other answers. Xcode can be really picky sometimes.

Tab instead of 4 spaces on visual studio code : Mac OS

I know that sound like a stupid question, and we can find many answer on google.
However, i've been trying for one hour and it still not working.
The question is prety simple, i'm coding on visual studio code on Mac OS.
And i want to instert tab when i press tab, and not 4 spaces.
It it supposes to be very simple :
Go on "code"->"preferences"->"users stting"
And add :
// Insert spaces when pressing Tab.
"editor.insertSpaces": false
Into : settings.json
However i have no clue why, but this is not working.
(I've save it, close visual, reboot mac, still not working)
Does anyone has any clues to help me?
Thanks a lot.
(I've save it, close visual, reboot mac, still not working)
--> One thing is missing - did you try it with a completely new file? ;)
I just tried it, had the same issue and almost thought it is a bug, but it seems to be expected behavior as there is another setting editor.detectIndentation which is true by default.
If the indentation is detected then the detected value takes precedence over your defined setting. At first this seemed odd as others also reported in a GitHub issue. But the analogy with CR/CRLF in this issue makes sense.
So as a quick fix you could set editor.detectIndentation to false or convert your existing indentation to tabs so that the next time you open the file the proper detection is done.

Xcode does not autocomplete memberwise initializer of a Struct

I am defining a struct like this in the Point.swift inside of my Xcode Project file:
struct Point {
var x: Int
var y: Int
}
If i am trying to init the Point struct from another file, Xcode does not autocompleting the memberwise initializer. Even if I have been restarted the machine as some friends suggest.
BUT autocompletion works fine, if i am defining initialising a new Instance in the same file or playground.
Any ideas how to fix this autocompletion issue?
This appears to just be a bug in Xcode. The first time you use an instance in another file, Xcode does not provide the autocompletion. But, the second time you use it it does.
Here is a demo of the strange behavior I am seeing. Even with the Point.swift file saved, the first time I use Point in ViewController.swift it doesn't autocomplete, but the second time it does:
This is with Xcode 7.2.
This bug is still actual in Xcode 10. As an addition to top answer: you can use explicit .init for autocomplete and then delete .init.
Get autocomplete to work with explicit init:
Point.init(x: x, y: y)
Delete .init and you'll end up with the expected code:
Point(x: x, y: y)
As Михаил Бабаев also said, I've still seen this issue in Xcode 10.1.
Typing
Point.init( brings up the default initialisers.
Then you could delete the 'init'
Save your files.
Xcode will autocomplete correctly once you've saved Point.swift
I know it seems weird, but although Xcode recognizes the struct and enables syntax coloring properly while editing the files, it still doesn't autocomplete completely until the struct source file is definitely saved (the file icon will change its background color).
I've had this behaviour in the past, and I was just able to reproduce it in a sample project.
If you type Point.init( Xcode suggests the init autocompletion.
More exciting news: starting from Xcode 10.2 this seems to be fixed, now if you tipe just Point( Xcode suggests the init method. Enjoy it.
I hit this same issue with Xcode Version 11.4.1 (11E503a). For me the issue was that my struct was defined in a different target than my app target. That target was imported in the file (in app target) I was trying to create an instance of that struct in. However, Xcode was never able to autocomplete the struct. I solved this by moving the definition of the struct to the app target and it autocompleted the memberwise initializer as expected.
Are we having fun yet?
For me it was a self induced error. I couldn't figure out why it wouldn't offer the autocompletion option. It took a few inspections of the struct to realize that even though I had a bunch of properties they were all defined as static - there was nothing to initialize! smh

Xcode & Playground not displaying results window

I am fairly new to programming, so I admit I have a lot to learn. In earlier versions of Xcode and Playground, I used to see the results as I typed a program. For example when typing
var str = "Hello, playground" on the far right (results window) I would see: Hello, playground. I also had typed up part of a program with a function and if I entered values for variables, it would calculate the result in the result window (on the right). At some point in typing program, it stopped showing this.
I was hoping that someone would be able to assist me in figuring out what happened. I am thinking that with trying to learn the new Mac (I have always used a PC in the past) that I may have pressed some buttons somewhere that I should not have....OR the newest updates took away the function somehow? Here is what I have done:
-closed the application and restarted
-restarted the computer
-tried checking setting, but I am not too sure what to look for...
-called for support but they don't seem too sure either..
-installed the newest version available of Xcode (Xcode 7 beta) and rebooted
Does anyone have any suggestions?
Thanks
I think this might be broken in 7B4, it is for me. I can see a thread on devforums for this, but when I clicked the link, it redirected me to a create-account page and would not let me in. When I tried to search for it from my account, I did not see it in the list.
See the thread shown in this (admittedly transient) search:
https://www.google.com/search?q=xcode+playground+not+showing+results&ie=utf-8&oe=utf-8
Particularly, this result:
Playground not displaying output | Apple Developer Forums
https://forums.developer.apple.com/thread/3672 Jun 9, 2015 - This
checks to see if the playground is operational. If it does not echo to
the results sidebar, try quitting and restarting Xcode. If you're
still not ...

Xcode user input: only first character shows up when inputting

When I am programming in Xcode (in C), and I am using the debugging console (brought forth with Cmd-R) to view the program and its output, and give it input, when I am entering input only the first character that I want to input shows up on the console. All the rest are invisible and non-selectable to me. Say I want to enter "20": all that shows up is "2". It still behaves as though I had entered all those characters (in the previous example, 20), so technically this bug (?) doesn't interfere with the actual software, but it's still annoying not to see all of the keystrokes that I had inputted previously. I just updated Xcode a day or two ago and installed Command Line Tools as well (though I doubt the latter is relevant). I believe the version number is 4.3 or so. Is anyone else having the same problem, and has anyone found a fix? Yes, I've tried restarting it.
I have the same problem.
It looks like it's a XCode 4.5 bug:
https://discussions.apple.com/message/19701332?tstart=0#19701332?tstart=0
So, you can wait or install a previous version.

Resources