First of all, i am not asking if its possible to pass data between view controllers. I am specifically asking if there is anyway to pass some values from a viewController thats in my project to a viewController inside a pod library !
The issue i am facing is that, i am using a payment SDK and the SDK doesn't support pay by saved card info. Normally , whenever i invoke a function from the SDK using a delegate in the sdk, a payment view is presented and it accepts inputs and the SDK works with those inputs.
But what i am trying to do is, pass values from saved card data (name number etc) to the viewController thats inside the pod library.
I tried creating a delegate on my class and tried to access it on the pod library viewController and it returned an error saying that it cannot find the item in scope. I tried creating a global variable and that also returned the same error.
So, this is my question. Is there anyway to pass data from my viewController to the viewController thats present in the SDK ?
You can, although it will be pointless to. Whenever you try to edit a file in the /Pods directory, it will warn you with something similar to the following message
You can press Unlock and append your code, or in your case, a delegate. But the next time you run pod install, it would override everything you've written.
The real pain starts when collaborating, as the /Pods directory does not get pushed into VCS.
I actually found a way to this. I made this happen by using sharedInstance
This is how i did it, here i created a sharedInstance variable.
#objc public final class NISdk: NSObject {
#objc public static let sharedInstance = NISdk()
//We will write the next function here//
}
Then i made a function that accepts parameters
#objc public func SavedCardPayment(cardToken : String,expiryMonth : String,
expiryYear : String,cvv : String,cardholderName : String,useSavingCards : Int)
{ // we will write some ways to store the values we just got as parameters// }
On this function
{
//You must declare these global variables somewhere inside the pod !
ViewControllerInsidePod.savedCardToken = cardToken
ViewControllerInsidePod.savedExpiryMonth = expiryMonth
ViewControllerInsidePod.savedExpiryYear = expiryYear
ViewControllerInsidePod.savedCvv = cvv
ViewControllerInsidePod.savedName = cardholderName
}
Now all info which user entered on the screen will be passed to SDK and then stored in these global variables (which are only available inside the pod n not in the project). Then i used these values to call a function of the pod from itself.
Now i will go back to my viewController in my project, and then call the function using sharedInstance
let sharedSDKInstance = NISdk.sharedInstance
let sharedSDKInstance = NISdk.sharedInstance
sharedSDKInstance.SavedCardPayment(cardToken : "\(token)",
expiryMonth : "\(expiryM)",expiryYear : "\(expiryY)",cvv : "\(cvv)",
cardholderName : "\(name)",useSavingCards : 1)
Hope this helps someone, i dunno if this is the right way to do it but this is how i passed data from a viewController that was outside of scope!
REMEMBER THIS
Also as #Visal Rajapakse , this will only work as long as you never update that specific pod !
I am designing a sdk where I am making some url call at some point of time. For this I want the context of the app which is making a call. As a context I want to pass the bundle identifier of the app using that sdk.
SDK is in form of library which some third party app will import and use. I have the reference of UIViewController which is invoking the url call in third party app. I have no idea if having only UIViewController reference is enough or not.
So how can I get access to bundle identifier of their app?
Thanks
It's quite easy.
Each type (class or struct) knows which bundle it is associated with.
Step 1# Get the type of any object inside the framework.
Step 2# Get the bundle of that type. And access its id.
// VC is ref to the class object of the main app
// # 1 -> This will give the class type of the object
let objectType = type(of: vc)
// # 2 -> This will get you the bundle of the main app
let bundle = Bundle(for: objectType.self)
// This will finally give you the bundle id
let bundleId = bundle.bundleIdentifier
I am attempting to integrate the Yelp API into my iOS app. From the existing yelp documentation for objective C, we downloaded their Xcode project and dragged it into our project. However, when trying to call and import the project in my swift file, we have errors. Here is what I mean:
func getYelpData(mapItem:MKMapItem) {
var term: String = (NSUserDefaults.standardUserDefaults().valueForKey("term") ?? "") as! String;
var location: String = (NSUserDefaults.standardUserDefaults().valueForKey("location") ?? "") as! String
var APISample: YPAPISample = YPAPISample() // Use of undeclared type 'YPAPISample'
and at the top of the class I try to import the YPAPISample like so
import YelpAPISample
but it does not allow me to do this either.
I'm new to swift programming so any help would be greatly appreciated!
It's one of the most regularly asked question regarding Swift on SO.
Apple provided a document here for such purpose:
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
In short, you'd need to create a bridge header to import the Objective-C framework. Not all the framework can be import directly in Swift.
To add it manually, search bridging in build settings: (Make sure you select All)
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.
I am trying to use private frameworks in my app which is not going to app store. Can anyone guide me, how to use private headers generated using class-dump in my ios application.
Below link is listing some private frameworks generated using class-dump. I am trying to import SringBoardServices.h in my MyClass.m file, but i am unable to access it. I am creating an object to SringBoardServices.h like
SringBoardServices *ref = [[SringBoardServices alloc]init];
and trying to access it's methods like ref.method_name. Whether it is a right approach to use private frameworks?
LINK: private-frameworks
I tried using Class myclass = NSClassFromString(#"SpringBoardServices");
id myobj = [[myclass alloc] init]; , but unable to access SpringBoardServices methods.