I am writing UITest for my app. In some parts of the UITest, I should call functions from Main target. When I create an Object from the Class(that has the implementation of the function), I get the error "use of undeclared of type CLASSNAME". I added the Class to the Compile Source of the test target.Then I get the same error but this time for the super class.
I added Classes to the compile source again and again, till I get this error "use of undeclared of UITextField, UIColor."
UITextField and UIColor are part of UIkit, then I import UIkit to my test Class , but did not work.
Any idea how to solve it?
In generell, How should we call functions in main target from test target?
Thanks a lot.
import your target with #testable import
import XCTest
#testable import MyProject
Related
After installing a framework into my project with Pod, I got the error message "Use of undeclared type ..." when I tried to create my own class by inheriting the class in the Library of the framework. But I can find the class in the Library by command-clicking the class in my file. Has anyone suffered from this problem before?
You need to import Former (the module of the library you are using) to use its functions.
import UIKit
import Former // <---
final class YourCell: UITableViewCell, LabelFormableRow {
...
I'm learning java and I'm told this package is provided by default, to every class, because its methods are so common. I thought I would try to import it, any way to see what would happen. I know its not practical and probably expensive but I'm curious as to why it's doesn't work from a technical point of view.
import javax.lang.*;//why doesn't this work.
javax.lang contains only a single package: model
https://docs.oracle.com/javase/7/docs/api/index.html?javax/lang/model/package-summary.html
you're not doing anything by importing this package. Maybe you're confusing it with java.lang ?
You don't need to import java.lang.*
There is one exception to the import rule. All classes in the java.lang package are imported by default. Thus you do not need to import java.lang.*; to use them without fully qualified names.
Consider the System.out.println() method we've been using since the first day of class.
System is really the java.lang.System class. This class has a public static field called out which is an instance of the java.io.PrintStream class. So when you write System.out.println(), you're really calling the println() method of the out field of the java.lang.System class.
In Apple's github for the Swift Package manager they use
import func POSIX.isatty
import func libc.strerror_r
import var libc.EINVAL
import var libc.ERANGE
import struct PackageModel.Manifest
source
There is also a file where the only code in it is #_exported source
#_exported import func libc.fileno
Is this a Swift 3 feature? I can not find anywhere that you can import a type in the Swift documentation and nothing on #_exported.
You can import only a specific part of a module, not a whole module:
Providing more detail limits which symbols are imported—you can specify a specific submodule or a specific declaration within a module or submodule. When this detailed form is used, only the imported symbol (and not the module that declares it) is made available in the current scope.
From Import Declaration
For example import func POSIX.isatty will import function isatty from module POSIX instead of importing the whole module POSIX (which is BIG).
The #_exported attribute starts with an underscore. That means it's a private Swift attribute. Not a feature, an implementation detail.
In short, this attribute lets you export a symbol from another module as if it were from your module.
Is it possible to import just one class from a Swift module? I used
import struct Foundation.Date
but now, NSString and other Foundation classes/structs are available too, at the top level!
All I really want is the Date class, to avoid polluting the namespace.
This answer is originally made for objective-c but the behaviour is the same: Why does a simple program import <Foundation/Foundation.h> instead of individual header files?
You don't have to worry about that, I think your compiler do this job perfectly ! :)
I have a class Comment declared as such:
public class Comment: NSManagedObject {
vars and methods...
}
When I try to compile my project, I get an error that reads:
Redefinition of 'Comment' as different kind of symbol
It highlights this line in the generated .h file: #interface Comment : NSManagedObject, and it tells me that the original declaration of Comment is in AIFF.h (something part of Foundation) and the line of the declaration is: typedef struct Comment Comment;.
I've only recently gotten this problem, and I've built the project with a Comment object successfully before. Why would an error like this happen in Swift?
Edit
If I remove the NSManagedObject superclass it compiles...
It may be a case that your class Comment is defined somewhere else in Foundation framework. What you need to do is importing only specific classes that you need inside your file. First remove all import statements in the source file and then import NSManagedObject like this:
import class CoreData.NSManagedObject
Then you will gain access to the NSManagedObject class you need for your Comment subclass. If you need any classes or structs from Foundation framework (for example NSError) you should import them like this:
import class Foundation.NSError
This will eliminate compiler errors about redefinition of class Comment.
Also make sure to clean the project and clean build folder by using Command + Shift + K and Command + Shift + alt + K