0

I'm new to Swift and i would be glad if anyone could help me to merge those two delegete written in two different languages. This is my problem:

ZZAppDelegate.h:

#import <UIKit/UIKit.h>
@interface ZZAppDelegate : UIResponder <UIApplicationDelegate>
@property(strong, nonatomic) UIWindow *window;
@end

ZZAppDelegate.m:

#import "ZZAppDelegate.h"
#import "PayPalMobile.h"

@implementation ZZAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


[PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction :@"TEST",PayPalEnvironmentSandbox :@"TEST"}];
  return YES;
}

@end

Both in Obj-C. I have to put them inside this AppDelegate.swift method:

import UIKit
import Parse

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow? 

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool     
{
      .
      .
      .

return true
}

If i try to move this (i wrote this in swift):

PayPalMobile.initializeWithClientIdsForEnvironments(PayPalEnvironmentProduction:"TEST", PayPalEnvironmentSandbox:"TEST")    

into my AppDelegate.swift method i get this error:

Extra argument 'PayPalEnvironmentSandbox' in call. 

This is the description about that method:

/// For example,
///  @{PayPalEnvironmentProduction : @"my-client-id-for-Production",
///    PayPalEnvironmentSandbox : @"my-client-id-for-Sandbox"}
+ (void)initializeWithClientIdsForEnvironments:(NSDictionary *)clientIdsForEnvironments;

Also, if i remove this extra argument i get this error:

Cannot convert the expression's type (PayPalEnvironmentSandbox: StringLiteralConvertible)' to type 'StringLiteralConvertible'

About this, i read into another question that: "Objective-C automatically promoted variables, Swift does not."

PS: I got two bridging header files, one with #import "PayPalMobile.h" and another one (for parse) with #import Bolts/Bolts.h .

IceHell
  • 1
  • 6

1 Answers1

0

Note the @{} in this call: initializeWithClientIdsForEnvironments: @{ PayPalEnvironmentProduction :@"TEST",PayPalEnvironmentSandbox :@"TEST" }

That's an ObjC NSDictionary literal, not the parameters to the method. (Note also that the declaration of initializeWithClientIdsForEnvironments that you quoted says its parameter is a dictionary.) You're trying to pass those things as parameters, when you should be constructing a (Swift) Dictionary literal instead — note the []:

PayPalMobile.initializeWithClientIdsForEnvironments([PayPalEnvironmentProduction:"TEST", PayPalEnvironmentSandbox:"TEST"])    
rickster
  • 124,678
  • 26
  • 272
  • 326
  • Thanks for reply rickster ! With those [ ] now seems to work but as @Craig Otis sayd, i need to provide a NSDictionary too right? Because now it gives me an "unwrapping an optional value" error probably provided by this nsdictionary miss. – IceHell Feb 18 '15 at 19:00
  • An `NSDictionary` in ObjC maps to an `[ NSObject: AnyObject ]` in Swift, and that's what the brackets provide. However, `PayPalEnvironmentProduction` may import as an optional, so you might need to unwrap it. Option-click it (and/or the `initializeWithClientIdsForEnvironments` call) in Xcode to see their Swiftified declarations to be sure. – rickster Feb 18 '15 at 21:09
  • If i option-click on Production it give me this: [link] (http://prntscr.com/66w87r), and for initialize: [link] (http://prntscr.com/66w8qc). I'll post here what should be the right result into the console: Environment: Optional("sandbox"). Accept credit cards? Optional(true) and this is what it gives to me: Environment: nil. Accept credit cards? nil fatal error: unexpectedly found nil while unwrapping an Optional value. But i can't understand why this error, i only moved from ZZAppDelegate.m the code into AppDelegate.swift and ain't touch anything else from the standard paypal code. – IceHell Feb 18 '15 at 22:45