Creating NSManagedObject subclass leads to linker error duplicate symbols - xcode

I am trying to create a nsmanagedobject (User) by going to the Editor menu and then selecting Create NSManagedObject Subclass...this generates four files:
User+CoreDataClass.h
User+CoreDataClass.m
User+CoreDataProperties.h
User+CoreDataProperties.m
In one of my viewcontrollers I import User+CoreDataClass.h and then have this code:
//create new account entity
User* thisUser = [NSEntityDescription
insertNewObjectForEntityForName:#"User"
inManagedObjectContext:self.myController.myDataManager.managedObjectContext];
When I then build the app, I get the following clang error:
duplicate symbol _OBJC_CLASS_$_User in:
/Users/xxxxxxxxxxxx/Library/Developer/Xcode/DerivedData/StarDate-fzkjccyoiwhfvvczdwkvkmtbioqw/Build/Intermediates/StarDate.build/Debug-iphonesimulator/StarDate.build/Objects-normal/x86_64/User+CoreDataClass.o
duplicate symbol _OBJC_METACLASS_$_User in:
/Users/xxxxxxxxxxxx/Library/Developer/Xcode/DerivedData/StarDate-fzkjccyoiwhfvvczdwkvkmtbioqw/Build/Intermediates/StarDate.build/Debug-iphonesimulator/StarDate.build/Objects-normal/x86_64/User+CoreDataClass.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I tried cleaning the app and deleting my derived data but that had no results. The only way I can clear the error is to delete the generated files. Which obviously is not going to be what I need. Why is XCode creating duplicate files off this menu command? Is there a setting that I missed?
Thanks

You are manually creating NSManagedObject subclasses, that Xcode 8 already has created for you and thus get duplicated symbols.
You can find detailed information how to solve this in this answer.

Related

Receiving a build error related to storyboard

I downloaded some Xcode projects from the Stanford University website.
But when I run them, I get the following two errors:
:-1: Build input file cannot be found: '/Users/myUserName/Documents/Stanford IOS/Lectures Swift Code/EmojiArt L13/EmojiArt/Supporting Files/Base.lproj/LaunchScreen.storyboard':-1: Build input file cannot be found: '/Users/myUserName/Documents/Stanford IOS/Lectures Swift Code/EmojiArt L13/EmojiArt/Supporting Files/Base.lproj/LaunchScreen.storyboard'
:-1: Build input file cannot be found: '/Users/myUserName/Documents/Stanford IOS/Lectures Swift Code/EmojiArt L13/EmojiArt/Supporting Files/Base.lproj/LaunchScreen.storyboard'
Here is the link to the project:
EmojiArtL12:
https://drive.google.com/drive/folders/1reg6-ZhLPIubmNO6aMDoTni-G728H0b0
I tried looking for answers on this board but couldn't find any.
Go to the 2 links in the error message, you will find the 2 files LaunchScreen.storyboard.xml -> change their file name to LaunchScreen.storyboard then it should build correctly. Hope this helps.

clang: error: no such file or directory: ...PrecompiledHeaders..../...pch

I have a project building correctly in one machine, but i am getting the following error when i try to build it in another. Both machines have the same version of OS X and XCode, and exactly the same source files.
clang: error: no such file or directory: '/Users/Cristian/Library/Developer/Xcode/DerivedData/MadGoose-alcvoermelusildxepcbneygiwbk/Build/Intermediates/PrecompiledHeaders/MadGoose_Prefix-afbukpnsoecegqeiiuwhfersynbx/MadGoose_Prefix.pch'
I have the following files on that directory
MadGoose_Prefix.pch.data
MadGoose_Prefix.pch.pch
MadGoose_Prefix.pch.dia
MadGoose_Prefix.pch.pch.hash-criteria
Anyone knows what could it be?
Or what should i compare between the machines?
I found the problem, i had this in the Build Settings
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"${FACEBOOKSDK}\"",
);
Since we don't use Facebook on the project anymore the variable ${FACEBOOKSDK} was empty in the machine with the problem, i remove it from there and problem solved.
An extra tip for others with build problems, check the XCBuildConfigutation section of the .pbxproj directly (Everything between /* Begin XCBuildConfiguration section */ and /* End XCBuildConfiguration section */), it was easy to spot the problem there, in XCode the variables are replaced with their value unless you edit them.

Swift: Undefined Symbols: iTunesApplication

I'm trying to create Swift OS X app now, and found difficulty using ScriptingBridge.
I included proper iTunes.h file, and Xcode is not giving any error when I wrote "iTunesApplication" as type.
However, when I compile(run) the app, it gives me error :(
Does anybody know about this issue?
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_iTunesApplication", referenced from:
__TFC12LoveYouChloe11AppDelegate10showWindowfS0_FPSs9AnyObject_T_ in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And here is my code:
var iTunes: iTunesApplication = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes") as iTunesApplication
iTunes.playpause()
The best way to solve this is to take the generated Objective-C Scripting Bridge header and convert it into a native Swift. I wrote a Python script (here) that can do that for you. You can see my answer here for a better explanation of what exactly is going on if you're interested.
Instead of
var iTunes: iTunesApplication = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
use
var iTunes: AnyObject = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
Sometimes the compiler gets confused when you are accessing two or more properties in a row(no idea why) so you may need to use a temporary variable. E.g.:
Instead of:
let songName: String = iTunes.playlists[0].songs[0].name
Try:
let song: AnyObject = iTunes.playlists[0].songs[0]
let songName = song.name
Or Alternatively the faster (this also works if you declare iTunes as an SBApplication) :
let songName: String = iTunes.valueAtIndex(0, inPropertyWithKey: "playlists").valueAtIndex(0, inPropertyWithKey: "songs").valueForKey("name")
EDIT:
You can also generate the .swift headers as specified here: https://github.com/tingraldi/SwiftScripting

Xcode error "Duplicate Symbol" causing Apple Mach-O Linker Error

duplicate symbol _leagueTableLoaded in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToMeViewController.o
duplicate symbol _showGLobalCompany in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToPositionViewController.o
duplicate symbol _leagueTableLoaded in:
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTGlobalResultsViewController.o
/Users/Brendan/Library/Developer/Xcode/DerivedData/2013-dbhrwzgxgwhfbqatgqpfrmqyucyu/Build/Intermediates/2013.build/Debug-iphonesimulator/2013.build/Objects-normal/i386/LTJumpToPositionViewController.o
ld: 3 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am getting the error above in xcode only when I try to build in simulator (on any iOS device I can build without error). I have three classes:
1.LTGlobalResultsViewController
2.LTJumpToMeViewController
3.LTJumpToPositionViewController
All three were created in xcode but both 2 & 3 have been modified outside of xcode and then rebuilt.
The #property bool leagueTableLoaded is defined in the header for all three. it is declared as:
#property bool leagueTableLoaded;
What is it exactly that is causing this error? I have tried the following:
I have tried renaming leagueTableLoaded in different classes but this doesn't fix it.
I have tried deleting my Derived Data files manually in library/developer/xcode folder.
According to other questions I have checked if I am importing a .m file. This is not the case. Apple Mach-O Linker error ("duplicate symbol")
Any other suggestions or advice?
Thanks,
James
ADDITION: As requested please find all the extracts from my .h and .m files that reference leagueTableLoaded or any of the variants I created when trying to get round this error:
LTJumpToMeViewController.h
#property bool leagueTableLoadedMe;
LTJumpToMeViewController.m
#implementation LTJumpToMeViewController
bool leagueTableLoaded = false;
LTGlobalResultsViewController.h
#property bool globalLeagueTableLoaded;
LTGlobalResultsViewController.m
#implementation LTGlobalResultsViewController
bool leagueTableLoaded = false;
LTJumpToPositionViewController.h
#property bool leagueTableLoadedPos;
LTJumpToPositionViewController.m
#implementation LTJumpToPositionViewController
bool leagueTableLoaded = false;
I can provide more information if required!
For me a duplicate symbol error came up when I absent mindedly included a .m file instead of a .h (Why does Xcode's autosuggest even show me .m files?!)
In this end this was being caused by the leagueTableLoaded bool being defined in both LTGlobalResultsViewController.m and LTJumpToPositionViewController.m.
Removing it from one of them fixed the issue. Although I'm not sure why it was there in the first place! Hope this helps anyone else who experiences the same issue! James
Xcode error “Duplicate Symbol” causing Apple Mach-O Linker Error is caused by duplicate symbols in Project. Steps to avoid error
Go to project -> Target ->Build Phases ->Compile sources
Check for the duplicate file (implementation file)
Delete the file and add it again
Clean and run project again
This worked for me. Hope it helps
In second view controller, you mistakenly #import "First.m", check it must be first.h file so replaces this with first.h. It's working for me.

can't share an archive in Xcode due to missing icon\r file

I put my Xcode project within my dropbox folder and now it seems like every time i try to share my archive from within the organizer it keep giving me the following error:
error: Codesign check fails : /var/folders/7l/l93zzs6n4h14qb7rmj5r7zn00000gn/T/GtLyx05w1O/Payload/stryker.app: a sealed resource is missing or invalid
In architecture: armv6
resource added: /private/var/folders/7l/l93zzs6n4h14qb7rmj5r7zn00000gn/T/GtLyx05w1O/Payload/stryker.app/www/Icon
resource missing: /private/var/folders/7l/l93zzs6n4h14qb7rmj5r7zn00000gn/T/GtLyx05w1O/Payload/stryker.app/www/Icon
I believe this error is caused by the fact that Xcode can see the icon/r file associated with drop box.
Is there a way i can delete this file?
I was able to share my archive after I deleted the icon\r file. Please refer to the following post for more info
https://apple.stackexchange.com/questions/31867/what-is-icon-r-file-and-how-do-i-delete-them/31877#31877

Resources