Xcode 6: Adding Existing Classes Produce Compilation Error - ios

I've just installed Xcode 6 and I've found that .. whenever I try to add an existing file to the project it produce a compilation error in the basic UIKit classes such as UITableView and NSObject ..
I have no idea why this is happening!

as per Shai and iDev answers i found that in xcode 6 there's no default PCH file .. so there's no default import for uikit and foundation .. it should be added manually .

Related

Can't compile old project after upgrade to Xcode 9/10 : "Expected unqualified-id" Error in GLKit / common.h

I have a IOS project I need to update.
It works fine in Xcode 8, but after upgrading to Xcode 9 or 10 (tried both) it won't compile anymore.
I get "Expected unqualified-id" parse error in the file "common.h" which is included from GLKit.h.
The line with the error is the following:
} /* extern "C" */
I think perhaps a } to much, however I can't even edit this file as it belongs to apples libraries and is read only.
If I go back to Xcode 8 it immediately works again.
I found out what happened. I had the following somewhere:
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
This messed up with something in the common.h.
Defining this after the include of the common.h solved the problem. I dont know why this only happens on XCode 9+

Build failed with error Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc

I am using Xcode 8.2.1. I am also using CoreData in my project.
When I try to generate a build or when I archive I am seeing the following error. Files mentioned in the error also changes at times.
ERROR:
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/BuildingRoofMapping+CoreDataClass.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/BuildingRoofMapping+CoreDataProperties.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/Region+CoreDataClass.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/Region+CoreDataProperties.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/StateRegionMapping+CoreDataProperties.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/WalkingDoors+CoreDataClass.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/WalkingDoors+CoreDataProperties.swift'
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
Here is how my CoreData Entities are configured:
Things I have Tried:
Check the location to see if files are actually missing, Files where present exactly at the same path.
I cleaned the build folder and removed derived data and build it again. Nothing helped.
Tried all the answers in this link. Nothing Worked.
Accepted Answer of this question doesn't seem to work either.
I am not sure why this error is coming. Any help is appreciated
EDIT
If I completely remove CoreData from my code then it Archives Successfully.
EDIT 2 :
When I change CodeGen to Manual/None and add files manually as suggested by #Anil . It builds successfully, But when I try to fetch the CoreData entity using :
let context = appDelegate.persistentContainer.viewContext
let buildingRoofMapping = BuildingRoofMapping(context:context)
It gives me run time error.
Error :
'NSInvalidArgumentException', reason: 'An NSManagedObject of class 'BuildingRoofMapping' must have a valid NSEntityDescription.'
EDIT 3:
Sample Code link. Run it in simulator. It crashes in fetchBasicPrice() of ViewController.swift file
I'll tell you what I have faced the same issue. In my case from Xcode 8 CoreData creates NSManagedObject class files in documents directory. I am sure you must have also created the same NSManagedObject files by your own.
You need to do following changes .xcdatamodel and regenerate a build. I have attached image below.
Make a change in Module and set it to Current Product Module and change the Codegen to Manual/None.
Let me know if you have more questions.
Below steps worked for me:
Change Module to Current Product Module and Codegen to Manual/None as suggested in Anil's Answer, for ALL the entities.
Manually Create CoreData files. For every entity two files are created.
One will be EntityName+CoreData with below contents :
import Foundation
import CoreData
public class EntityName: NSManagedObject {
}
another will be named : EntityName+Properties
import Foundation
import CoreData
extension BasicPrice {
#nonobjc public class func fetchRequest() -> NSFetchRequest<BasicPrice> {
return NSFetchRequest<BasicPrice>(entityName: "BasicPrice");}
#NSManaged public var var1 : String?
#NSManaged public var var2 : Int32
#NSManaged public var var3 : Float
#NSManaged public var var4 : Bool
}
NOTE:
This kind of class/structure is not my developed, it is followed by CoreData internally when we select Class Definition from CodeGen.
Hope it helps someone!
First, If you are checking or running the code in simulator and on changes in coreData code you are getting crashed, then you need to delete the app from the simulator and then again install and run. By doing this, changes that are made in your code do not make crash or show error.
I am writing it as an answer because I am not allowed to comment yet.
From your comments I have assumed that you have cleaned the derived folder as well as deleted the app from simulator as well as from device while building on it.
Did you try setting Build Active Architecture Only flag to No in the Project settings tab? If not please do that as well.
While archiving, the app will be built for all targets. And thus some issue might surface which you would have missed by setting the flag to Yes during development.

failed to import bridging header file in swift

I am getting this error while running this project.
failed to import bridging header '/Users/OdysseyApps/Desktop/ashraf/onedrive-sample-sync-ios-master/OneAPI Sync/OneAPI Sync-Bridging-Header.h'
I think the problem is the space in project name OneAPI Sync.
please give me some suggestion.
Probably You have imported some class in bridge file.
That is not a part of your bundle.(or didn't accidentally imported .m file)
Try to find that class and remove that class import statement.

Xcode playground 'no such module 'SQLite' ' how to add module to it?

hi it's my first time to post.
I'm now doing a tutorial on Xcode 8.2.1 playground using SQLite from below website:
https://www.raywenderlich.com/123579/sqlite-tutorial-swift
I downloaded a Xcode source containing a playground and a SQLite project, and i uploaded it to the following path.
https://github.com/TerryDon2017/My-SQLite.swift-master-tutorial.git
I have the error message below:
Playground execution failed: error: SQLite.playground:1:8: error: no
such module 'SQLite' import SQLite
^ thread #1: tid = 0x1cd7d, 0x00000001094e9360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground, queue =
'com.apple.main-thread', stop reason = breakpoint 1.1
I was told to do 2 things:
1.drag the SQLite.xcodeproj to the workspace
2.set the build dependency
i think I did 1 ok but for 2 i could not find anyway to set the dependency for the playground. could you please kindly help? thanks!

Swift: Error when trying to import UIKit

I'm getting this really weird error when trying to import UIKit in my swift file.
My Code is simply:
import UIKit
class Test: NSObject {
}
The error I get at 'import UIKit' is:
Unknown type name 'import'
Expected ';' after top level declarator
I have added UIKit to my Frameworks folder, the class doesn't contain any code (so therefore there shouldn't be anything wrong with it) and I tried to restart both xCode and my Mac, but the error is still there.
I appreciate any help.
Thanks.
EDIT:
Solved:
I tried to import 'Test.swift' in AppDelegate.
This problem usually happens when you try to import ".swift" file in your Objective-C code, like this: #import "HomeViewController.swift". This is wrong and you should import special, automatically generated Swift header, instead:
#import "ProductModuleName-Swift.h"
where ProductModuleName is the name of your module (or project) containing the Swift code.
Found good Trouble shooting guide - there is great Troubleshooting Tips and Reminders section!
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_87
The import stuff in swift is case sensitive. Example :
import uikit
will not work. You'll have to type it as
import UIKit
In my case, it was because somehow the selected type in the file inspector was objective-c source instead of Default - Swift Source even though i was using a .swift file.
Changing it to Default - Swift Source solved the issue for me.

Resources