Can't use realm framework in Swift 2 application - ios

I'm running the latest beta of El Capitan along with the latest Xcode 7 Beta.
I'm trying to import the Realm framework to use in my iOS application. I've followed the specific instructions for the Swift 2 installation and imported the Realm and RealmSwift frameworks into the embedded binaries.
I copied the files over and my Framework Search Paths is set to $(SRCROOT) - recursive.
On trying to build I'm getting "No such module 'Realm'" and it starts giving build errors on getting JSON values
I've tried importing RealmSwift instead and I receive this error
I've done all the recommended steps, cleaning, deleting derivedData, even moved my source code to a new project all with the same error.
Does anyone have any recommendations on how to solve this issue?

Related

Xcode 9 Swift Language Version (SWIFT_VERSION)

I've recently updated xcode to version 9. Before that in Xcode 8.x whenever I use to do pod update it shows me an update code to convert the code to Swift 3 and doing that solve the errors. But now it is giving me this error:
The “Swift Language Version” (SWIFT_VERSION) build setting must be set
to a supported value for targets which use Swift. This setting can be
set in the build settings editor.
For this error I've tried Build Settings > Swift Language Version and it was Swift 3.2
But as the update call has re-installed some of the pods like Alamofire and it says to install Xcode 8.x to convert the code to Swift 3 so do I need to install an additional version with the latest Xcode? If yes, then how can I install Xcode 8 with Xcode 9?
Answer to your question:
You can download Xcode 8.x from Apple Download Portal or Download Xcode 8.3.3 (or see: Where to download older version of Xcode), if you've premium developer account (apple id). You can install & work with both Xcode 9 and Xcode 8.x in single (mac) system. (Make sure you've Command Line Tools supporting both version of Xcode, to work with terminal (see: How to install 'Command Line Tool'))
Hint: How to migrate your code Xcode 9 compatible Swift versions (Swift 3.2 or 4)
Xcode 9 allows conversion/migration from Swift 3.0 to Swift 3.2/4.0 only. So if current version of Swift language of your project is below 3.0 then you must migrate your code in Swift 3 compatible version Using Xcode 8.x.
This is common error message that Xcode 9 shows if it identifies Swift language below 3.0, during migration.
Swift 3.2 is supported by Xcode 9 & Xcode 8 both.
Project ► (Select Your Project Target) ► Build Settings ► (Type 'swift' in Searchbar) Swift Compiler Language ► Swift Language Version ► Click on Language list to open it.
Convert your source code from Swift 2.0 to 3.2 using Xcode 8 and then continue with Xcode 9 (Swift 3.2 or 4).
For easier migration of your code, follow these steps: (it will help you to convert into latest version of swift supported by your Xcode Tool)
Xcode: Menus: Edit ▶ Covert ▶ To Current Swift Syntax
For Objective C Projects created using Xcode 8 and now opening in Xcode 9, it is showing the same error as mentioned in the question.
To fix that, Press the + button in Build Settings and select Add User-Defined Setting as shown in the image below
Then in the new row created add SWIFT_VERSION as key and 3.2 as value like below.
It will fix the error for objective c projects.
I just got this after creating a new Objective-C project in Xcode 10, after I added a Core Data model file to the project.
I found two ways to fix this:
The Easy Way: Open the Core Data model's File Inspector (⌥⌘-1) and change the language from Swift to Objective-C
Longer and more dangerous method
The model contains a "contents" file with this line:
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14460.32" systemVersion="17G5019" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
In there is a sourceLanguage="Swift" entry. Change it to sourceLanguage="Objective-C" and the error goes away.
To find the "contents" file, right click on the .xcdatamodeld in Xcode and do "Show in Finder". Right-click on the actual (Finder) file and do "Show Package Contents"
Also: Changing the model's language will stop Xcode from generating managed object subclass files in Swift.
This can happen when you added Core Data to an existing project.
Check the:
<Name>/<Name>.xcdatamodeld/<Name>.xcdatamodel/contents file.
This file contains an entry "sourceLanguage" that (by default) might have been set to "Swift". Change it to "Objective-C".
I just click on latest swift convert button and set App target build setting-> Swift language version: swift 4.0,
Hope this will help.
This Solution works when nothing else works:
I spent more than a week to convert the whole project and came to a solution below:
First, de-integrate the cocopods dependency from the project and then start converting the project to the latest swift version.
Go to Project Directory in the Terminal and Type:
pod deintegrate
This will de-integrate cocopods from the project and No traces of CocoaPods will be left in the project. But at the same time, it won't delete the xcworkspace and podfiles. It's ok if they are present.
Now you have to open xcodeproj(not xcworkspace) and you will get lots of errors because you have called cocoapods dependency methods in your main projects.
So to remove those errors you have two options:
Comment down all the code you have used from cocoapods library.
Create a wrapper class which has dummy methods similar to cocopods library, and then call it.
Once all the errors get removed you can convert the code to the latest swift version.
Sometimes if you are getting weird errors then try cleaning derived data and try again.
maybe you need to download toolchain.
This error occurs when you don't have right version of swift compiler.
In my case, all warn disappeared after I directly changed swift version from 2.x to 4.0 in build settings except two warn.
These warning related to myprojectnameTests and myprojectnameUITests folder. I didn't notice and I thought its relate to direct immigration from Xcode 7 to Xcode 9 and I thought I couldn't solve this problem and I should install missed Xcode 8 version.
In my case, I deleted these folders and all warns disappeared, but you can recreate this folder and contains using this:
file > new > target > (uitest or unittest extensions)
and use this article for create test cases:
https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/04-writing_tests.html

Cannot load module 'UIKit' as 'UIKit'

Currently trying to open an app created in Swift 3, Xcode 8.1. I have done tonnes of research, deleting derived data and cleaning the entire project over and over. I have updated Xcode to its newest version, as well as syntax. MapKit may be interfering but I doubt it. It's a really small project with only 2 VC's. I directly downloaded the project from a website (https://www.pubnub.com/blog/2015-05-05-getting-started-ios-location-tracking-and-streaming-w-swift-programming-language/) and after installing the pods required I still get the error. I am also opening the workspace, not just the project itself. If there is any more information you require, let me know and I will provide it.
Perhaps it was spelled incorrectly?
I wrote UIkit instead of UIKit and got this error:

How do I use Realm in a Swift Playground?

So, I'm pretty new to XCode development, but I've read the documentation on how to import third party frameworks into a Playground in XCode 7.1.1, and the documentation on how to get started with Realm, using the Dynamic Framework method of installation.
At this point I have a workspace that contains an iOS project, the two .framework folders required by Realm, and a Playground project. I have built the workspace without errors.
I figured going through some of the Realm examples in the Playground would be a great way to get going, but doing a simple:
import RealmSwift
results in a "No such module 'RealmSwift' error. What am I missing?
You should install Realm with Cocoapods.
One good practice to adopt is using Cocoapods when using other librairies like this one when they support it. That way you always have control on the version you're using of this library.
Update: Realm Swift works with Swift Playgrounds now. You'll find an example in Realm's release zips (direct download).
Realm doesn't support Swift Playgrounds at the moment: https://github.com/realm/realm-cocoa/issues/938
I faced the same issue while playing with RealmSwift on a Playground. I create it under a single view iOS application. Fixed it after building my main target, as creates the dynamic framework to be linked into the Playground.
Working fine with Cocoapod installation, Swift 4.2, & Xcode 10.1
Try it yourself. https://github.com/sauvikdolui/RealmExploration

Xcode 7 Swift Framework Cannot import module being compiled

My framework WebCoreDataStaticLibrary was working fine with ios 8.3 in Xcode 6.3. After I updated to ios 9 and Xcode 7 I am not able to compile my framework. This framework contain both swift and Objective C classes.
I have converted to To Latest Swift Syntax via Xcode
In any swift classes where I have imported WebCoreDataStaticLibrary its coming Cannot import module being compiled.
import WebCoreDataStaticLibrary Cannot import module being compiled
As a result I am not able to build the framework As a result getting this fatal error.
fatal error: lipo: can't open input file: /*/Developer/Xcode/DerivedData/A3WebCoreDataStaticLibrary-ctaegtiwmwhrsdeggeswpkjvucua/Build/Products/Debug-iphonesimulator/A3WebCoreDataStaticLibrary.framework/A3WebCoreDataStaticLibrary (No such file or directory) Command /bin/sh emitted errors but did not return a nonzero exit code to indicate failure
Project Settings
It's telling you the problem. It can't find A3WebCoreDataStaticLibrary.framework/A3WebCoreDataStaticLibrary.
I even know why. There is no directory on your file system named /*/.
Something in your project settings is set wrong. My guess is your Framework Search Paths is wrong, or the Link Binary With Libraries section is wrong. Without knowing what's in your project settings, it's hard to tell.
UPDATE The screenshot shows a different error than the description.
At this point, you need to start digging. Go to that directory. Make sure that file exists.
If the file doesn't exist, you need to look at the A3WebCoreDataStaticLibrary target and see why it's not building the framework where you expect it to be.
If the file does exist, then you need to check the build order. It may be building the framework after it tries to build your app.

Xcode cannot parse exported project from Unity 4 after being upgraded from unity 3

We upgraded a 9 month old Unity project, which is currently on the appstore, to Unity 4.1, and after the conversion, when we export the Unity-iPhone.xcodeproj in Xcode, we get the following error:
Project cannot be opened because the project file cannot be parsed.
We already tried the solutions here:
Unable to open project... cannot be opened because the project file cannot be parsed
Has anyone else ever had this parse error when trying to open an xcode project after being exported from Unity?
Some Unity packages install editor scripts that modify the XCode project after it's generated. These scripts can cause the symptom described, if they have a bug, or if they subtly interfere with each other. Search your project for OnPostprocessBuild calls, try disabling them one-by-one, generate a fresh XCode project each time, and see if it starts opening with XCode.
If it does start working, diff the working and non-working versions of Unity-iPhone/project.pbxproj, and see if you can figure out why.

Resources