I'm trying to build a framework to export a few classes as an importable "package of sort".
My Framework project is called "MyFramework"... is was created as a Cocoa Touch Framework project in Swift.
I've added a single swift file called ImplementationTest.swift
It contains the following :
public class ImplementationTest {
public init(){
print("Init called");
}
public func echo(request: String){
print ("Echo called with "+request);
}
}
The framework builds fine and I get a MyFramework.framework folder.
I add that framework to a new swift application project and added it as Linked Framework and Library as well as Embedded Binaries.
I can "import MyFramework" just fine.
But if I try "var test=ImplementationTest()", I get the following error :
use of unresolved identifier "ImplementationTest"
If I try "var test=MyFramework.ImplementationTest()" I get :
module 'MyFramework' has no member name "ImplementationTest"
Am I doing this wrong ? Can my framework only have one single exported class ? and should it be named the same name as the framework itself ?
Check after you build the framework if you can access it via in, show finder.
If not, then try building it using generic ios device.
Related
I'm trying to import/use this project in my Swift application, but the compiler throws tons of error with following message:
No known class method for selector 'indexPathForRow:inSection:'
Following is the typical code which generates the above error:
if ([self tileForIndexPath:[NSIndexPath indexPathForRow:row inSection:i]].empty) {
...
}
I can able to run the downloaded project as an standalone application without having any problem, though.
I've also added all the frameworks to my main application - those were used and installed to the said project, but that didn't help. My main project's deployment target is 10.0.
indexPathForRow:inSection: is a static constructor method that creates NSIndexPath instances. It is defined in UIKit:
https://developer.apple.com/documentation/foundation/nsindexpath/1614934-indexpathforrow?language=objc
In this project the author imports UIKit in the pch file:
https://github.com/austinzheng/iOS-2048/blob/7c0840a0f7bd77b01d6a36778a253f8f4b2e6529/NumberTileGame/NumberTileGame/NumberTileGame-Prefix.pch#L14
So you have 2 options: either setup a pch file for Objective-C code in your project (create the file and add to Xcode project build settings), or in each source file where you get this error add #import <UIKit/UIKit.h>.
I import a swift framework to a swift project, but when I call the class in this framework, Xcode throw a compile error "Use of undeclared type 'xxxx(class name)' ".
I feel Xcode have found the framework, otherwise it will complaint "can't find xxx(framework name)".
But why Xcode can't find the class of this framework.
I have tried remove and re-add framework, and delete DeivedData files, but all of them not work. I haven't use CocoaPods to import framework.
Any idea?
In a Framework that was built for Release (and not Debug), the class symbols need to be accessible.
Make sure you are you trying to access Public or Open classes from your Swift framework.
// set the Framework class to Public
public class rnHello{
// set the initializer to public, otherwise you cannot invoke class
public init() {
}
// set the function to public, as it defaults to internal
public static func world() {
print("hello from a static method")
}
}
Now you can access this via your Swift code or if you attach lldb using:
lldb) po rnHello.world()
Make sure that the FrameWorkSearch path in the BuildSettings of the project is reflecting the correct path to your framework.
i create a swift framework, and create a objectivC file in the framework project.
swiftClass.swift:
Public swiftClass{
func test(){
var c = objectivCClass();
}
}
objectivCClass.h:
#Interface objectivCClass{
}
#end
I know make objectivCClass.h to public header in Build Phases , and import it in swiftFramework.h , the framework can works ok.
But I do not make objectivCClass public in Build Phases and do not want user knows the class. If I make objectivCClass.h to project/private header , An error happen.
Who know how to handle it?
I have a custom swift framework that I am trying to access via my project.
The method in my framework is
public func test(url:String, callType:String){
}
and I am trying to access it from my main project with
import FrameworkName
FrameworkName.FrameworkSwiftClass.test()
The problem is that it looks like it is looking for
FrameworkName.FrameworkSwiftClass.test(FrameworkSwiftClass)
Why is XCode telling me extra argument when I try
FrameworkName.FrameworkSwiftClass.test(url:"url", callType:"type")
You are using the method as if it was a static method but it's not, you have to instantiate your class first:
let framework = FrameworkName.FrameworkSwiftClass()
framework.test(url:"url", callType:"type")
Simple function in swift for testing:
func testExample() {
var tagname = "someClass()"
var logger = Device("", "") //unresolved identifier
XCTAssert(true, "Pass")
}
Even after I import my module with "import ", I still cannot use classes from my module. Also though I might have messed something up in the project, but NONE of my sample projects will let me use module classes.
Seems like it should work but might have broken in beta 2.
EDIT: fixed it
The IDE didn't pick up the check for the param names. Seems Xcode is still a tad iffy
I hit the same issue today, not sure if this is only available recently - rather than using import TARGET_NAME in your test file and/or declaring your classes/methods as public, you can add your file to your Tests target via XCode's File Inspector.
Cmd + Opt + 1 to show it while in any file, and check the box under Target Membership for your Tests Target.
You may need to rebuild.... Cmd + b.
Should this be specific to my system.... I'm running Xcode 6.3 beta 1, and testing via Quick + Nimble, both installed with the latest cocoapods beta.
The problem for me was that I had non-alphanumerical characters in my main target name.
I had to import it the following way (Note the special #testable annotation)
#testable import my_tutorial_app
It seems that in Xcode 6 Beta 4 you need to declare public classes and methods as "public". Example:
public class Device {
public init(...) {
}
public func myMethod(...) {
}
}
Now they are accessible from the swift test class.
I had the same problem and discovered that it works if I call it like this:
SuperStructName.StructName