Class name conflict with class in Framework - ios

In main project, I have a class named: Result.
And I import a third framework through Cocoapods which is also named Result. The Result framework has a class named Result.
In project, how can I use the Result class in Result framework?

You need to put the package name in front of the class name.
ThirdPartyFrameworkName.Result
and
YourTargetName.Result

Related

Swift Framework - public class results as undeclared type

I've written a custom framework in swift. This framework has a lot of classes... and all these classes have been marked as public.
public class Person{
...
}
When I import my framework into another project I would expect to be able to use the Person class since it has been marked as public but I'm actually getting an error message saying that Person is an undeclared type.
These are the steps that I follow to include the framework into my project:
Drag framework into the project in Xcode
Add the framework to embedded binaries and to Link binaries with Libraries if is not there already
import the framework where I need to use it with import MYFramework
Am I missing anything?!
You should add public init method
public init() { }

Declare a class with the same name in two different Swift frameworks

I have 2 Swift frameworks FrameworkA and FrameworkB. I have another framework Common. Common has an open class BaseClass.
FrameworkA has an internal class Class that inherits from BaseClass.
If I now try to declare an internal class named Class in FrameworkB which inherits from BaseClass, I get an error saying its an invalid redeclaration of Class.
I of course tried cleaning the derived data and everything, but no luck. I'm on Swift 3. My current workaround is to name the one in FrameworkB differently.

Namespace Conflict in swift with cocoa pod module

I have an enum in one of my Swift files called Foo.
One of the Cocoapods called NameA also has the same enum with name Foo (public enum, not inside any class).
This module also has a class with the same name as its framework NameA.
If I try to refer to Foo in NameA module like this:
NameA.Foo
It doesn't work because the compiler thinks I'm referring to the class NameA, but not the module NameA.
The workaround posted here wont work for me either Swift namespace conflict
This seems to be a reported bug in swift:
https://bugs.swift.org/browse/SR-898
Don't import NameA.
Instead, import enum NameA.Foo (notice the keyword "enum", can also be used for "struct" or "class" or "func")
Reference either Foo (your enum) or NameA.Foo (their enum).
If you need to reference NameA in the same file as NameA.Foo:
Create a new file for your "wrapper" type:
import NameA
typealias NameAWrapper = NameA
Reference the class NameA as NameAWrapper in your other files without importing the module directly.
This was inspired by this workaround (which you linked to), but modified slightly based on your situation: https://stackoverflow.com/a/26774102/358806
I ran into a similar issue recently. You won't like the solution I found, but I'll share it anyway. I had to fork the pod I was using and rename it to something new. The new project name no longer conflicted with the class name and I was able to namespace it as MyForkedName.ClassName. This is really an inconvenient way to do it, but in our case it was an older library that hadn't changed in some time (and one we will be removing altogether in the future) so I was willing to settle for now.
If you want to use enum from other module like Cocoapods or some framework you have to use this approach,
suppose I have enum Result defined in my project and same in some other module. You want to use both enum in same file then-
import enum MyFramework.Result
func doSomething(callback: (Result<Data>) -> Void) {
}
func doSomething1(callback: (MyFramework.Result<Data>) -> Void) {
}

Xcode automatically prefixing file names

Since Xcode 6.2 it wants to prefix a filename with its type.
So a "Test" UIViewController now is named:
UIViewController+Test.h,
UIViewController+Test.m
rather than Test.h, Test.m.
I have tried 6.3 and 6.4 beta and they all exhibit this habit. How do you stop it?
Many thanks.
You created a category, not a class.
When you use the “Objective-C File” template, you can create an empty file, a category, a protocol, or a class extension. You cannot create a class using the “Objective-C File” template. Here's what it looks like when you create a category:
To create a class, you need to use the “Cocoa Class” template. Here's what it looks like when you create a class:
It will automatically add the class name as a prefix for categories, if that's what you mean:
Select IOS -> Source -> CocoaTouch Class and the select UIViewController then write your class name Test by removing UIViewController which is alrady present in class name. If you write your class name first then select UIViewController then it will appear attached with your class name

Swift Compiler Error: Use of unresolved identifier 'name'

I tried to include a class called 'name' and I got an error:
Swift Compiler Error: Use of unresolved identifier 'name'
The class exists and doesn't contain any compile errors.
There could be a few possible issues.
One of the classes has a Testing target and other one doesn't. You have to even include all of your classes in the testing target or none of them.
If it's Objective C class, check that the class is in ObjectiveC bridging header file.
If it's NSManagedObject subclass. Add #objc(className) before the class declaration.
If it's part of a different framework, make sure that the class or function is public
I had this one too. You will probably find that your first class is included in your testing module and that "name" isn't. Simply, if you include a class in testing, then every class that it references has to be in testing.
I had this problem too. I was trying to reference Class 1 within the code in Class 2. My problem was that Class 2 had target memberships in A and B, and Class 1 only had Target Memberships in Class A.
You can fix this by opening the Utilities Tab (farthest right button on the top bar of the Xcode window), and make sure that the same boxes are checked for both classes in the Target Membership subsection.
Got problem solved by
Target -> Build Phases -> Compile Sources -> Adding the class file
Add one more to the list.
If it is part of another framework, make certain that the "Build Active Architecture Only" settings are the same.

Resources