How to get swift mangled object name - swift

I've learned that swift actually creates a naming method called "mangling" used internally for all objects.
All threads talk about demangling, but how to actually get the mangled name?
i've tried
1- object_getClass(self)
2- NSStringFromClass(MyClass.self)
but they return the normal class name.
I've found this demangle project..
https://github.com/mattgallagher/CwlDemangle/blob/master/CwlDemangle/CwlDemangle.swift
is there a mangling project maybe?
Note: Im using swift 3.0.1

xcode ships with a command line tool to de-mangle names.
Type in:
swift demangle
Then find your mangled class name..
__TMaC17find_the_treasure15YD_Secret_Class
Then watch it spit out the name..
find_the_treasure.YD_Secret_Class
If you want to observe the mangled names, as you asked, you can put the produced Swift iOS or macOS binary into a dissassembler like Hopper, iDAPro or radare2.
The tools to automatically de-mangle names are already here (refer to Hopper v4.0 Dissassembler).

Related

Obj C codebase and unit test cases in Swift

I have an objective c code base and I am writing snapshot test cases in swift. I have certain functions and variable which are declared in .m class. How I can access those variables from swift test class.
Use a bridging header to expose the Objective-C entities that you want to use in your Swift tests. You may already have one set up (as explained in the link, Xcode offers to create one when you add a Swift file to an Objective-C project); if so, you may just need to update the file to add headers that aren't currently included. If you don't have one, the link I provided will show you how to create one.

Can I use Extension to end a method name in swift 4.2?

Can I use Extension to end a method name in swift 4.2? the compiler is suggesting to clip the name, like registerExtension() to register(), while registerMyname() works fine.
Note: registerExtension() & registerMyname() are part of my Objective C framework.
Compiler suggest a name because of in current version of Swift you're using there's a method exists with a new name which defined in your Objective-C frameworks. By accepting of suggestions it doesn't change anything it works as well as it works before.

Xcode build error - Multiple commands produce .o, Target 'ProjectCoreData' has compile command for Swift source files listed twice

I am running xCode Version 10.1 (10B61), Mojave 10.14 (18A391)
Searching shows similar issue in Xcode 10 greater than a year ago, but no issues since then. The solution from last year seemed to be switching to legacy mode, but that doesn't work now. It appears the source code that is stored on my desktop is conflicting with code that is in 'DerivedData', I'm not sure why this would suddenly pop up so randomly.
I see this problem go away if I remove the last model added in Core Data. It seems to trigger when I add a relationship to another object. It's apparently random.
Any advice on how to fix this issue so I can develop?
Multiple commands produce '//Library/Developer/Xcode/DerivedData/ProjectCoreData-ehjvvgovpitmbcegzopwciptfafr/Build/Intermediates.noindex/ProjectCoreData.build/Debug-iphonesimulator/ProjectCoreData.build/Objects-normal/x86_64/Contact+CoreDataClass.o':
Target 'ProjectCoreData' (project 'ProjectCoreData') has compile command for Swift source files
Target 'ProjectCoreData' (project 'ProjectCoreData') has compile command for Swift source files
from the logs:
<unknown>:0: error: filename "Contact+CoreDataClass.swift" used twice: '/Users/<user>/Desktop/ProjectCoreData/Contact+CoreDataClass.swift' and '/Users/<user>/Library/Developer/Xcode/DerivedData/ProjectCoreData-ehjvvgovpitmbcegzopwciptfafr/Build/Intermediates.noindex/ProjectCoreData.build/Debug-iphonesimulator/ProjectCoreData.build/DerivedSources/CoreDataGenerated/ProjectCoreData/Contact+CoreDataClass.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "Contact+CoreDataProperties.swift" used twice: '/Users/<user>/Desktop/ProjectCoreData/Contact+CoreDataProperties.swift' and '/Users/<user>/Library/Developer/Xcode/DerivedData/ProjectCoreData-ehjvvgovpitmbcegzopwciptfafr/Build/Intermediates.noindex/ProjectCoreData.build/Debug-iphonesimulator/ProjectCoreData.build/DerivedSources/CoreDataGenerated/ProjectCoreData/Contact+CoreDataProperties.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
The reason you see this error is because Core Data creates these files by default, but you can't see them in Project Navigator. Then you create a duplicate (in Editor/Create NSManagedObject Subclass). As a result you have your error.
According to What's new in Core Data here is a picture with the solution:
For future users :
If you are using core data and If you copied entity using option+drag, then ensure that entity name and class name must be same.
None of the solutions mentioned over internet worked for me.
It happened to me after I dragged the coredata model and classes from another project, which generated duplicate files. If this is your case, go to TARGETS->Build Phases->Compile Sources, remove the duplicate files and it should be working again.
for me it was simple problem,
i had 2 source files of the exact same name,
just renamed one of them (only the swift file name) and the problem was gone
To fix this I've to open the .xcdatamodeld using finder/show package content
This image
and then repeat this operation with the .xcdatamodel.
This option
After this I've opened the file (I use Sublime) Sublime Text locate the duplicate class name Duplicate Class Name, change it, save the file and build again. Like this

Play! Framework Templating Engine issues importing long class names

I've got a List of classes I want to send down to a Scala Template in Play! Framework 2.2.3
however I ran into some issues while trying to do so.
The class I want the list to contain is an arbitrary class type that comes from a package outside of my workspace, but not natively from Java. See the picture below.
Note: I do not have a project/Build.scala file.
The above image represents the first line in my scala template, I have tried to use #import as well (#import com.***.***.type._, com.***.***.type.Version, etc) but to no avail.
This is the error message given to me by Play! Framework.
Is there an issue with the namespacing? Everything works fine when using classes located in my workspace.
The Paths are correct, I've double checked that. For reasons I cannot disclose more code in this region, if more information is required please ask for it and I'll edit the post.
The problem is related to package named type. This word is reserved in Scala as language keyword. You need to escape it like this:
#import List[com.your.package.`type`.Version]

C++ forward reference in IOS Project (forward references to 'enum' type)

I'm using a SDK in one of my projects and when adding in the libraries etc, I get an error from this line of code, which is from inside a .h file. I cannot change the .m since its not available to me. Its inside .a (lib)
-(enum scanDeviceID)ID;
And the error message is:
Semantic Issue
ISO C++ forbids forward references to 'enum' types
Are there any compilier/build setting that I can modify to make this work?
Failing that, I know very little C++, is there something on the line of code I can change to make it work?
The line of code says that this method returns an element that's named in the scanDeviceID enum. The problem is that the compiler doesn't see a declaration of that enum. Somewhere in a .h file you should have that declaration. Importing the file should fix it.