I'm making a migration from Swift 2.3 to Swift 5 with a lot of pain and well, I'm ending the migration but I'm still getting an error in some places of the code:
Notification' is ambiguous for type lookup in this context
I recieved before this error but now I'm getting this in places like
var notifications = [Notification]
self.notifications = (sql.execute() as NSArray) as! [Notification]
and
func isAlreadyExists(notification: Notification) -> Bool {
I thought to change Notification name but the app is not mine and is big... very big and is not possible to do this and well, I don't know what to do.
Thanks in advance.
Edit:
Tried to do the same as suggested in How can I disambiguate a type and a module with the same name? but doing "import (class|struct|func|protocol|enum) Module.Symbol" desn't works (I see where Notification is in the project but doesn't work ProjectName.class).
Finally, it worked by changing the class name and adding it to a file called <Project_name>-Bridging-Header.
Doing this I could call the class with var example = <Project_name>.<className>
I am currently using the latest version of Parse 1.14.2 and Bolts 1.8.4.Parse is implemented correctly and I have been using it for a long time now. The problem I'm facing now is when I try to use Parse's local datastore. I have the following code in my AppDelegate.swift:
Parse.enableLocalDatastore()
Parse.setApplicationId("ID",
clientKey: "Client_Key")
I have the following code to create and save a string named firstName in a class named contact:
let contact = PFObject(className: "contact")
contact["firstName"] = "Jack"
contact.pinInBackground()
Here is the code to retrieve objects from the created class:
let query = PFQuery(className: "contact")
query.fromLocalDatastore()
query.getFirstObjectInBackgroundWithBlock({ (object, error) -> Void in
if error == nil {
if let contact = object {
print(contact.objectForKey("firstName"))
}
}
})
I have added libsqlite3.dylib to my project. My app doesn't crash when I run this code but it simply gives me the following message when I try to retrieve objects:
2016-08-29 11:31:38.049 App_Demo[14436:3504319] [Bolts] Warning: `BFTask` caught an exception in the continuation block.
This behavior is discouraged and will be removed in a future release.
Caught Exception: Method requires Pinning enabled.
Can anyone help me to work around this issue? I am guessing the issue is that this version of Bolts cannot pin Parse objects in the background and I need to work my way around this bug. Any help would be appreciated as I have been stuck at this for a while and can't find too much info online.
Edited: I have tried downgrading Bolts, but then Parse downgrades with it in Cocoapod and it causes errors in Xcode.
it's not objectforkey.
You need to call object["UsedName"] "UsedName" being the key. Hope that helps.
I created an iOS8 application and updated it to XCode7. I have a couple of problems after I recreated the NSManagedObject.
First I get an error, if I fetch for contacts and iterate over them:
let contacts = try self.managedObjectContext.executeFetchRequest(request) as! [Contact]
for contact in contacts{
//--> EXC_BAD_INSTRUCION
}
Contact is my NSManagedObject. I do not get any compiler error or warning.
Second: I get this warning:
CoreData: warning: Unable to load class named 'MyAppName.Contact' for entity 'Contact'. Class not found, using default NSManagedObject instead.
What can cause this? The #objc(Contact) in Contact has already been generated bei XCode and now I can't set the className MyAppName.Contact in CoreData-editor. Any suggestion?
Finally found it. All the other tips are not working, because Apple has changed it with XCode7.
Now XCode creates #(Classname) in the NSManagedSubclass. This needs to be commented out (beta1 and beta2). Then XCode can find your class.
So I have been making an app, and everything has been working great. But today I made a new class like usual and for some reason in this class I can't access Public/Global variable from other classes. All the other classes can, but now when ever I try to make a new class I can't. How would this be fixed?
I am using Swift and Xcode 6.
Working Class:
import UIKit
import Foundation
import Parse
import CoreData
var signedIn = true
class ViewController: UIViewController {
New Class:
import UIKit
class NewClass: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
signedIn = false
}
But on signedIn = false
I get the error:
use of unresolved identifier "signedIn"
One possible issue is that your new class has a different Target or different Targets from the other one.
For example, it might have a testing target while the other one doesn't. For this specific case, you have to include all of your classes in the testing target or none of them.
Once I had this problem after renaming a file. I renamed the file from within Xcode, but afterwards Xcode couldn't find the function in the file. Even a clean rebuild didn't fix the problem, but closing and then re-opening the project got the build to work.
'Use of Unresolved Identifier' in Swift my also happen when you forgot to import a library. For example I have the error:
In which I forgot the UIKit
import UIKit
Sometimes the compiler gets confused about the syntax in your class. This happens a lot if you paste in source from somewhere else.
Try reducing the "unresolved" source file down to the bare minimum, cleaning and building. Once it builds successfully add all the complexity back to your class.
This has made it go away for me when re-starting Xcode did not work.
Another place I've seen this error is when your project has multiple targets AND multiple bridging headers. If it's a shared class, make sure you add the resource to all bridging headers.
A good tip to is to look in the left Issue Navigator panel; the root object will show the target that is issuing the complaint.
For me this error happened because I was trying to call a nested function. Only thing I had to do to have it fixed was to bring the function out to a scope where it was visible.
In my case, I had an Object-C file which was also in the same Target Membership. I fixed by adding #import "YourObjectCFileHeader.h" inside file Bridging-Header.h
Because you haven't declared it. If you want to use a variable of another class you must use
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var DestViewController : ViewController = segue.destinationViewController as ViewController
DestViewController.signedIn = false
}
You have to put this code at the end of the NewClass code
Your NewClass inherits from UIViewController. You declared signedIn in ViewController. If you want NewClass to be able to identify that variable it will have to be declared in a class that your NewClass inherits from.
I got this error for Mantle Framework in my Objective-Swift Project.
What i tried is ,
Check if import is there in Bridging-Header.h file
Change the Target Membership for Framework in Mantle.h file as shown in below screenshot.
Toggle between Private Membership first build the project , end up with errors.
Then build the project with Public Membership for all the frameworks appeared for Mantle.h file, you must get success.
It is just a bug of building with multiple framework in Objective-C Swift project.
If this is regarding a class you created, be sure that the class is not nested.
F.e
A.swift
class A {
class ARelated {
}
}
calling var b = ARelated() will give 'Use of unresolved identifier: ARelated'.
You can either:
1) separate the classes if wanted on the same file:
A.swift
class A {
}
class ARelated {
}
2) Maintain your same structure and use the enclosing class to get to the subclass:
var b = A.ARelated
I did a stupid mistake. I forgot to mention the class as public or open while updating code in cocoapod workspace.
Please do check whether accesor if working in separate workspace.
You forgot to declare the variable. Just put var in front of signedIn = false
My issue was calling my program with the same name as one of its cocoapods. It caused a conflict. Solution: Create a program different name.
This is not directly to your code sample, but in general about the error. I'm writing it here, because Google directs this error to this question, so it may be useful for the other devs.
Another use case when you can receive such error is when you're adding a selector to method in another class, eg:
private class MockTextFieldTarget {
private(set) var didCallDoneAction = false
#objc func doneActionHandler() {
didCallDoneAction = true
}
}
And then in another class:
final class UITextFieldTests: XCTestCase {
func testDummyCode() {
let mockTarget = MockTextFieldTarget()
UIBarButtonItem(barButtonSystemItem: .cancel, target: mockTarget, action: MockTextFieldTarget.doneActionHandler)
// ... do something ...
}
}
If in the last line you'd simply call #selector(cancelActionHandler) instead of #selector(MockTextFieldTarget.cancelActionHandler), you'd get
use of unresolved identifier
error.
First off, I know similar questions have been asked before and I've tried following the advice of this stackoverflow answer here to no avail. I also tried adding the basic gist of this as a comment, but I don't have enough rep yet :( Basically I am trying to use PFSubclassing to extend Parse's PFUser model. As such, here's my corresponding code:
User.swift:
import Foundation
import CoreLocation
class User : PFUser, PFSubclassing {
override init() {
super.init()
}
convenience init(email: String!) {
self.init()
self.email = email
self.username = email
}
// don't need to call User.registerSubclass() in AppDelegate because this
// is handling that here
override class func load() {
self.registerSubclass()
}
// Commented out because this is extending PFUser
// override class func parseClassName() -> String! {
// return "PFUser"
// }
}
Result on Tests:
-[PFObject _loadSensitiveUserDataFromKeychainItemWithName:]: unrecognized selector sent to instance 0x7f98ebc1c250
I'm also doing the following in my Bridging-Header:
#import <Parse/Parse.h>
#import <Parse/PFObject+Subclass.h>
If I un-comment "parseClassname() in User.swift" I get:
failed: caught "NSInvalidArgumentException", "Cannot initialize a PFUser with a custom class name."
Which leads me to believe that setting up the interfaces is at least partially working.
Based on all of the advice I've seen, I can't seem to figure out what I'm doing wrong. There is also an open bug that produces the same error message, but it is caused by using Parse's local data store and I haven't configured any of that.
At this point I feel like I am missing something dead obvious, or I am being affected by the same bug as mentioned above. Any suggestions?
Okay, solved my own problem here through trial and error. Essentially it looks like a cached logged in PFUser was causing problems. When Parse would initially load it was loading the logged in state from the emulator which was conflicting with the newly registered User subclass.
To fix this you can either:
Restart the emulator.
Call PFUser.logOut() right after Parse.setApplicationId() in AppDelegate to flush the cached user.
Hopefully this helps someone else out in the future!
I solved this issue by changing the initial view controller. It didn't register the user because it didn't go through the view controller that previously stated/identified who the user was.
What I did specifically:
Set the initial view controller, for the controller that captures who the user is and then segue your way past to where you want to be.
Restart the simulator.