Passing variables between files in swift 2 not working with Struct method - swift

Im using Xcode 7.2 and I wanted to pass a variable between .swift files. I tried using static variables inside structs as such: in file 1 and then use this variable as such in file 2. But Xcode doesn't recognize the struct. What am I doing wrong? Thanks!

You need to specify that SomeStruct is defined in File1.
So the new variable in File2 would be declared as:
var someOtherVar = File1.SomeStruct().someVariable

Related

How do you create a UTType for System Declared Uniform Type Identifiers for folder?

I see all kinds of examples for using a file or an extension but I am trying to call let imag = NSWorkspace.shared.icon(for: <#T##UTType#>) and I don't see any init method in UUType that takes a identifier e.g. folder.
UTType is declared in the Uniform Type Identifiers framework.
All uou need to do is import UniformTypeIdentifiers and then you'll be able to write things like UTType.folder.

Save variables into a struct from the workspace

As you can see in the picture, I have three variables, two are named number_of_steps_... and the third one is struct.
How can I save the content saved in the number_of_steps variables into struct?
I have tried the save command but that doesn't work for what I need. What is the right way to do this?
I don't know what you mean by "save", but you can add them to the struct by using
mystruct.number_of_steps1 = number_of_steps1
mystruct.number_of_steps2 = number_of_steps2
Then save the struct to a file using
save mystruct.mat mystruct
Notice I've taken the liberty of renaming the variable struct as mystruct. Since "struct" is a Matlab command, it's not a good idea to use it as a variable name.

Is it possible to edit the value of a public variable from another module?

Can you edit the value of a public variable from another module or does that variable have to be open.
My understanding of public/open in swift 3 is:
Public classes can be made in another module but only open classes can be subclassed in another module.
Public functions can be called in another module but only open functions can be overwritten in another module.
But I am unsure about about variables.
You most definitely can! Here is a great way you can accomplish it:
In the module that contains the variable that you wish to manipulate:
// Must be declared globally
public var someValue = "hi"
In a different module that you wish to manipulate the variable from:
// Initialize the module that holds the variable you want to manipulate
var myModule = SomeModule()
// Manipulate the variable (someValue)
myModule.someValue = "bye"
The variable someValue will now have a value of "bye"

Define a typealias for the whole project

In which file can I define a typealias that works in the whole project, etc.
typealias S = String
the typealias works the same way as variables. If you want to be global put it outside the class scope at any file.
typealias is use to aliasing the existing Data Types. Its access scope is same as a variable, if its declared in side the block like class, struct, protocol etc then its visibility also remains inside that block only. it can not be used outside to declare a new variables of that type.

Can't access constants from one swift file in another

I'm converting some code from Objective C to Swift so I can get a handle on Swift.
Basically, in Objective C, I had a header file containing some global constants which were accessible in other Objective C classes.
I changed my .h file to be .swift and changed the constants to look like:
public let INVALID_INTEGER_VALUE = (-32768)
public let INVALID_LONGLONG_VALUE = (0x8000000000000000)
...
But when I try to access these in another Swift file, the compiler gives "Use of unresolved identifier..." I tried importing my .swift file, but that also didn't work (as far as I can tell, I shouldn't need to import any of my swift files as they are part of the same module).
Any thoughts?
You could also run into this if the file that is trying to use the constant has been added to another target (like the tests target) that the file containing the constants has not been added to.