Swift Vscode Class in Other File Not Recognized

VSCode: search classes / go to class for imported libraries

Try using go to symbol in workspace (bound to T by default). This should be implemented by dart and other language extensions.

It's up to each extension to determine how this feature works. JS/TS includes symbols from imported libraries for example, but this behavior may differ between extensions

Swift coding in visual studio code

Yes, you can code Swift on Windows. Check out RemObjects Silver which gives you a Swift compiler in Visual Studio 2015. Visual Studio Express is free, but I don't know if it works with Silver.

Swift itself is just a language. In order to build an iOS app, you need frameworks and libraries like Foundation and UITouch (which can be written in any language, in this case: C, Objective-C and C++). Apple has open sourced many Foundation classes and ported them to Linux but there are lot of stuffs that are not fully implemented or there are bugs in Linux that don't exist in OS X. There's no official Windows port. I doubt Apple will ever open source UITouch at all.

Silver can target .NET (and I guess by extension its cross-platform cousin Mono), Java or Sugar (vendor's proprietary framework). If you want to use Swift on Windows, yes, you can, but don't expect to build an iOS app on Windows. If you are serious about iOS development, buy a Mac, even the $500 Mac Mini can go a long way. If you only want to play with Xcode, assemble a Hackintosh or a virtual machine so that you can run OS X.


Update June 2020: at WWDC 2020, Apple announced Swift 5.3 will expand to include support of Windows and more Linux platforms:

Swift 5.3 is a release meant to include significant quality and performance enhancements. In addition, this release will expand the number of platforms where Swift is available and supported, notably adding support for Windows and additional Linux distributions.

There is official support for Swift on Windows 10. It works with Visual Studio 2019 (not VS Code). Install Swift on Windows

code . is not recognized as an internal or external command

It needs to be setup so that Code is found in your PATH. If you're on a mac system, do the following (for windows systems, read below):

  1. Launch VS Code
  2. Open up command palette (press F1) and type shell command to find Shell Command: Install 'code' command in PATH command.
  3. Restart terminal

VSCode screen capture

If you're on Windows, you can also set the PATH manually by adding:

C:\Program Files (x86)\Microsoft VS Code\bin

to your PATH environment variable.

  1. Open command prompt
  2. Type the command - setx path "%path%;C:\Program Files (x86)\Microsoft VS Code\bin"
  3. Restart terminal

Update: If you're on Windows 10 and VSCode 1.47.2 and above, the new PATH has to be set to:

C:\Users\{username}\AppData\Local\Programs\Microsoft VS Code\bin

VSCode show `unrecognized token` for Objective-C header file

Try disabling the standard c/c++ extension (vscode-cpptools). It will treat all .h files as normal c/c++ headers by default, so objective-c specific syntax will produce an error.

As an alternative, you may also be able to change the files.associations for .h files to mark them specifically as objective-c. Not all extensions will respect the files.associations however

Swift class property reference points disappear after init method

With some help from our C developers we've found the reason for this issue.

Swift when variable is passed to a method - copies the root of the reference but holds the same references for it's children which caused issues with how C library checked the reference values. This didn't happen when everything was in one method because only local references were passed and they were not copied.

Example:

variable1 :: refId = 0x001
variable1.prop1 :: refId = 0x0011
variable1.prop2 :: refId = 0x0012
variable1.prop3 :: refId = 0x0013

Reference passed to the C library:

(copy) variable1 :: refId = 0x002
variable1.prop1 :: refId = 0x0011
variable1.prop2 :: refId = 0x0012
variable1.prop3 :: refId = 0x0013

The library checked if an array reference point was different then first value reference point. If so it assumed that the array was not empty.

Since the main reference was copied hence had different reference point, the code assumed there was some value which in fact didn't exist and we got bad_access due to trying to access a non-existant reference.

The issue was solved with changing the register() method to receive the parameters as inout instead of using self.

Example based on previous mockup :

class Account {
var accId: c_library_type = 0
var accCfg: c_library_type2 = c_library_type2()

init()
{
c_config_setting_defaults(&self.accCfg)
//other code
}

public func register(id: inout c_library_type, cfg: inout c_library_type2)
{
c_register_method(&id, &cfg)
}
}

//Somewhere else in the code

var account: Account = Account()
account.register(id: &account.accId, cfg: &account.accCfg)

Thank you for your time to anyone who commented on the issue.



Related Topics



Leave a reply



Submit