Use of unresolved identifier CNContact [swift 3] - ios

In swift 2, this below line works
var contacts = [CNContact]()
But in swift 3 it's got 'Use of unresolved identifier CNContact' error message. I tried both insert and delete import Contacts since xcode 8 ignoring import because the viewcontroller is already part of module 'Contacts'. How to solve it?

It's perfectly working in Swift 3.0. I have just created a new project and I can freely use CNContact.
Possible Workaround:
Delete Derived Data
Clean your project
Now try to build your project.

Related

Use of undeclared identifier when I want use swift file in objective c project

when I want use swift file in objective c project and I declare an object from swift class, I get "Use of undeclared identifier" error.
the way that I pass:
coping swift file in project and type #objc before declare swift class
create header file in project manually
set "Defines module" in target to Yes
set objective-C bridging header in target to $(SRCROOT)/$(PRODUCT_MODULE_NAME)-Bridging-Header.h
declare #import "productModuleName-Bridging-Header.h" in objective-c file
use name_of_swift_class *s = [[name_of_swift_class alloc] init];
when I want use swift file in step 6 I get "Use of undeclared identifier" error. why?!!! do I have the mistake?
when I test this steps in new project I don't get error but in project that I want it return error.
thank you for your help
The problem is at Step 5 You should not be importing "productModuleName-Bridging-Header.h" instead you should be importing "productModuleName-Swift.h"
P.S- After making this change clean your project, clear your derived data and build it. It will work. Hope it helps :)

objective-c use cocoapods add Swift framework not found file

I'm working on an objective-c project. I added a swift framework, which gave me errors.
When I touch "command" can find the file. When I use #import also can add "ChartLineView.swift".
But when I implement it as,
ChartLineView *cl = ....
I get an error, " Use of undeclared identifier LineChartView"
What could be wrong?
I guess your are having issue in importing swift library(added via cocoapods) in your Objective C project. Just go in your .m file and import the swift library like this.
#import LineChartView; // i suppose LineChartView is the swift library name.

Parse SDK and Swift: Incorrect argument label in call PFObject 'withoutDataWithObjectId'

I subclass PFObject exactly as described here.
Then I create a new instance of the subclassed object without data, but since Swift 1.2 I get an error (It did work perfectly before):
var test = Armor(withoutDataWithObjectId: "1234567890")
-> Xcode complains:
"Incorrect argument label in call (have 'withoutDataWithObjectId:',
expected: 'className:')"
Why className? It should get the class name from the class function parseClassName
And I can under no circumstances create a new object with objectId but no data (which I MUST have to fetch it from the local datastore)
This is super annoying as my app doesn't compile any longer.
Update to the newest Parse SDK, available here.
The issue is caused due to necessary adaptions in the Parse SDK after the Swift language update. This issue also occurs with the most recent update to Swift 2.2. The newest (as of today) Parse SDK release 1.13.0 already fixes this.
UPDATE
Parse iOS SDK 1.13.0 has a typo and the function PFUser(withoutDataWithObjectId:) is called PFUser(outDataWithObjectId:). So upgrading the Parse SDK alone does solve this. Until this is fixed a temporary workaround would be to extend PFObject with a convenience initializer. To do this add a new Swift file to your project and insert this:
import Parse
extension PFObject {
convenience init(withoutDataWithObjectId objectId: String?) {
self.init(outDataWithObjectId: objectId)
}
}
It may be a little late to answer this question.
I use swift 1.2, and v 1.7.5 Parse SDK, and it works totally fine.
however, make sure you have define objective-c bridging header in "build setting".
and try to run it, even though there may reports some error

PFObject does not have a member named 'saveInBackground' in Xcode 6.0.1, Yosemite GM3

Parse is acting very strangely in Yosemite, saveInBackground claims to not be a member of PFObject.
var score = PFObject(className: "score")
score.setObject("Mo", forKey: "name")
score.setObject(1, forKey: "scoreCount")
score.saveInBackground()
Clearly this should work, perhaps it's an issue with Xcode 6.0.1 or Yosemite GM3 (Or a combination). To be clear, using saveInBackgroundWithBlock works fine.
Has anyone else experienced this or a similarly weird bug?
The saveInBackground method is declared in the header to return a BFTask * object, which is part of the Bolts framework. Make sure your project is linking the Bolts framework, and then add
#import <Bolts/Bolts.h>
to your bridging header.
This solved a few "missing" APIs in Swift for me (this one, as well as PFAnalytics.trackAppOpenedWithLaunchOptions mentioned here: Why does my PFAnalytics not have trackAppOpeneWithLaunchOptions function? (IOS SWIFT)
If you don't want to mess around with the Parse framework files, you should replace:
score.saveInBackground()
with:
score.saveInBackgroundWithTarget(nil, selector: nil)
No need for bridging headers since release 1.0. To fix the issue, just add, import Bolts at the top of your class, below import Parse:
import Parse
import Bolts
With the added import statement, saveInBackground() should work as is.
ok, got it, in the parse,framework open up headers, go to PFObject.h and open it, navigate to where it says #name Saving Objects and write down this:
(void)saveInBackground;
run the app or close and open again Xcode and try to write down again the code and saveInBackground should be now an PFobject of your score.
this work
testObject.saveEventually()

Install Realm in a Swift App

I am trying to add Realm to my app written in swift. I have followed the tutorial and I can't seem to get it to work. The biggest problem is that when I try to import Realm I get No such module 'Realm' I don't know what else to try. You can see my efforts below.
You can see the instructions here: http://realm.io/docs/cocoa/0.85.0/#swft
I have also copied the instructions below:
Due to the current lack of proper infrastructure for Swift dependency management, using Realm in your project requires the following steps:
Add Realm as a submodule by opening the Terminal, cd-ing into your top-level project directory, and entering the command git submodule add git#github.com:realm/realm-cocoa.git
Open the realm-cocoa folder, and drag Realm.xcodeproj into the file navigator of your Xcode project.
In Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the “Targets” section in the sidebar.
In the tab bar at the top of that window, open the “Build Phases” panel.
Expand the “Target Dependencies” gorup, and add Realm’s iOS framework.
Expand the “Link Binary with Libraries” group, and add Realm’s iOS framework as well as libc++.dylib.
Click on the + button at the top left of the panel and select “New Copy Files Phase”. Rename this new phase to “Copy Frameworks”, set the “Destination” to “Frameworks”, and add Realm.framework.
Drag the file at realm-cocoa/Realm/Swift/RLMSupport.swift into the file navigator of your Xcode project, unchecking the “Copy items if needed” checkbox.
Below is what it looks like in my project:
I am not sure exactly why this isn't working, but here is a workaround:
Follow the latest instructions.
Create a bridging header, for example by
Add a new Objective-C class to your xcode project.
Agree to have a bridging header created
Delete the Objective-C class
Add this in the bridging header:
#import "Realm/Realm.h"
Remove any Import Realm statements from your code, including from RLMSupport.swift
Now it should work. For example, I test with putting this in my ViewController.swift
import UIKit
class Person: RLMObject {
dynamic var name = ""
dynamic var birthdate = NSDate(timeIntervalSince1970: 1)
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let author = Person()
author.name = "David Foster Wallace"
// Get the default Realm
let realm = RLMRealm.defaultRealm()
// Add to the Realm inside a transaction
realm.beginWriteTransaction()
realm.addObject(author)
realm.commitWriteTransaction()
// Print all Persons
println(Person.allObjects())
}
}
Which prints:
RLMArray <0x7a243760> (
[0] Person {
name = David Foster Wallace;
birthdate = 1970-01-01 00:00:01 +0000;
}
)
I have been talking with the guys at Realm, and it turns out that the latest instructions don't work with Realm <= 0.85 They changed they way the build the framework and it won't work anymore. They said they will release 0.86 later today that should fix the problems anyone is having with Swift. In the meantime I have a test project that anyone can take the latest framework from. https://github.com/smitt04/testRealm
Version 0.86 is now out and this is no longer an issue.
The Swift installation instructions were long and convoluted, so I'm not surprised you and several other users ran into issues.
Please follow the latest installation instructions here.

Resources