venmo / venmo-ios-sdk

Make and accept payments in your iOS app via Venmo
MIT License
178 stars 57 forks source link

sendPaymentTo() Swift "Extra Argument 'audience' in call #64

Closed sanjams2 closed 9 years ago

sanjams2 commented 9 years ago

I keep getting a compile Error in Xcode: Extra Argument 'Audience' in call when I try to call my sendPaymentTo() method. Below is the code I have written

var audienceType = VENTransactionAudience.Private
Venmo.sharedInstance().sendPaymentTo(self.name?.text, amount: self.amount?.text.toInt(), note: self.note?.text, audience: audienceType, completionHandler: { (transaction,success,error) -> Void in
            if success {
                println("success")
            }
            else
            {
                prinln("Error")
            }

})

I have tried deleting Audience as a field and it says that I am lacking an argument 'audience' when I do so. I have also tried passing in nil and "private" as parameters for this argument.

Has anyone else experienced the same problem or recognize my mistake?

eliperkins commented 9 years ago

This seems to work fine for me in Xcode 6.3 (after fixing the prinln to println in the error state). Do you have any more information about the error? Maybe a screenshot or more error logs?

sanjams2 commented 9 years ago

screenshot 2015-02-17 21 14 42 jpeg

Thats all Im getting. It does not build.I am on Xcode 6.1.1. Do you think that is the problem?

eliperkins commented 9 years ago

Hm. I'd be curious to see if you continue to have issues on Xcode 6.3. If so, we can continue to debug, but with Swift in flux to much, I'm not inclined to make changes to an Obj-C project such as this without fully considering the implications of using our SDK in Swift.

Try Xcode 6.3 for me and let me know if you continue to have these warnings!

sanjams2 commented 9 years ago

screenshot 2015-02-18 17 20 23 jpeg

Yeah I'm continuing to get Errors. Would it possibly be because my amount is an int and not Uint? Or possibly because they are all optionals? Sorry to pretty much make you debug my code, but Im wondering as well if this is a swift issue. Thanks

eliperkins commented 9 years ago

I'd say the optionals are the cause of this one. Try unwrapping the optionals and passing them to the sendPaymentTo method. Since Obj-C can't handle optionals, I'd say this has probably been the root cause of the initial issue, Xcode 6.3 is just giving you a better error now.

sanjams2 commented 9 years ago

Unwrapping the optionals worked. I think the problem in the end was also that the toInt() function returns an optional value as well. For those who run into this same problem: I converted the string from the text field to a float * 100 converted that value to a int an converted that value to a UInt

converting straight to an Int will truncate the decimal places so the float value *100 is necessary and I could not find a conversion straight from float to uint so I by passed this by converting from float to int to uint.

schan93 commented 9 years ago

@jsanders67 I am also having this issue. I have tried to unwrap the optionals with the ! and also tried to listen to your advice to convert the text field to a float * 100 but I can't seem to get it to work. Below is what I have tried: Any advice? screen shot 2015-03-24 at 2 22 41 am

sanjams2 commented 9 years ago

I believe you need to convert that float value to an Int and then again to a UInt. I'm not totally sure as to why the Venmo SDK uses the UInt, but thats what seemed to work for me.

I would also make sure your text fields are not blank by unwrapping all of them before you envoke the sendPayment() request to the Venmo Shared Instance. If one of the text fields is left blank and the IBAction is invoked, an unable to unwrap nil exception will occur at runtime and could cause your app to freeze and lock up in production.

This was my code: (ignore the print statements, makePayment method just invokes the send Payment method with the Transaction Audience being private)

if ((self.name?.text == nil) || (self.amount?.text == nil) || (self.note?.text == nil)) { println("Name Field Left Blank (name?.text == nil)") println("Amount Field Left Blank (amount?.text == nil)") println("Note Field Left Blank (note?.text == nil)") } else { println("Envoking make Payment") println("(newAmount)") let nonOptional = (newAmount! as NSString).floatValue * 100 println("(nonOptional)") let intAmount = Int(nonOptional) println("int Amount = (intAmount)") let finalAmount = UInt(intAmount) makePayment(newName!, newNote: newNote!, newAmount: finalAmount) } }

Not efficient and should be slimmed down, but gets the job done.