2014-07-08 16 views
7

Sto cercando di importare this library nel mio progetto Swift. Sto facendo tutto passo dopo passo da this document e this answer, ma niente funziona.Uso del tipo non dichiarato nel progetto Swift

Ecco il mio screenshot: enter image description here

Ecco il mio Bridging-header.h:

// 
// Use this file to import your target's public headers that you would like to expose to Swift. 
// 

#import <UIKit/UIKit.h> 

#import "VKUser.h" 
#import "VKAccessToken.h" 
#import "VKCache.h" 
#import "VKStorage.h" 
#import "VKStorageItem.h" 
#import "VKRequestManager.h" 
#import "VKRequest.h" 
#import "VKConnector.h" 
#import "VKMethods.h" 

#import "NSData+toBase64.h" 
#import "NSString+Utilities.h" 

La cosa importante è che ho classe VKConnector e il protocollo VKConnectorDelegate in un unico file. Forse questo è il problema?

// 
// Copyright (c) 2013 Andrew Shmig 
// 
// Permission is hereby granted, free of charge, to any person 
// obtaining a copy of this software and associated documentation 
// files (the "Software"), to deal in the Software without 
// restriction, including without limitation the rights to use, 
// copy, modify, merge, publish, distribute, sublicense, and/or 
// sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following 
// conditions: 
// 
// The above copyright notice and this permission notice shall be 
// included in all copies or substantial portions of the Software. 
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
// THE SOFTWARE. 
// 

#import <Foundation/Foundation.h> 
#import <UIKit/UIKit.h> 
#import "VKMethods.h" 
#import "VKAccessToken.h" 
#import "VKStorage.h" 
#import "NSString+Utilities.h" 
#import "VKStorageItem.h" 


@class VKConnector; 


static NSString *const kVKErrorDomain = @"kVkontakteErrorDomain"; 


typedef enum 
{ 
    kVKApplicationWasDeletedErrorCode 
} kVkontakteErrorCode; 


/** Protocol incapsulates methods that are triggered during user authorization 
process or access token status changes. 
*/ 
@protocol VKConnectorDelegate <NSObject> 

@optional 
/** 
@name Show/hide web view 
*/ 
/** Method is called when user needs to perform some action (enter login and 
password, authorize your application etc) 

@param connector VKConnector instance that sends notifications 
@param webView UIWebView that displays authorization page 
*/ 
- (void)VKConnector:(VKConnector *)connector 
    willShowWebView:(UIWebView *)webView; 

/** Method is called when UIWebView should be hidden, this method is called after 
user has entered login+password or has authorized an application (or pressed 
cancel button etc). 

@param connector VKConnector instance that sends notifications 
@param webView UIWebView that displays authorization page and needs to be hidden 
*/ 
- (void)VKConnector:(VKConnector *)connector 
    willHideWebView:(UIWebView *)webView; 

/** 
@name UIWebView started/finished loading a frame 
*/ 
/** Method is called when UIWebView starts loading a frame 

@param connector VKConnector instance that sends notifications 
@param webView UIWebView that displays authorization page 
*/ 
- (void)VKConnector:(VKConnector *)connector 
webViewDidStartLoad:(UIWebView *)webView; 

/** Method is called when UIWebView finishes loading a frame 

@param connector VKConnector instance that sends notifications 
@param webView UIWebView that displays authorization page 
*/ 
- (void) VKConnector:(VKConnector *)connector 
webViewDidFinishLoad:(UIWebView *)webView; 

/** 
@name Access token 
*/ 
/** Method is called when access token is successfully updated 

@param connector VKConnector instance that sends notifications 
@param accessToken updated access token 
*/ 
- (void)  VKConnector:(VKConnector *)connector 
accessTokenRenewalSucceeded:(VKAccessToken *)accessToken; 

/** Method is called when access token failed to be updated. The main reason 
could be that user denied/canceled to authorize your application. 

@param connector VKConnector instance that sends notifications 
@param accessToken access token (equals to nil) 
*/ 
- (void)  VKConnector:(VKConnector *)connector 
accessTokenRenewalFailed:(VKAccessToken *)accessToken; 

/** 
@name Connection & Parsing 
*/ 
/** Method is called when connection error occurred during authorization process. 

@param connector VKConnector instance that sends notifications 
@param error error description 
*/ 
- (void)VKConnector:(VKConnector *)connector 
    connectionError:(NSError *)error; 

/** Method is called if VK application was deleted. 

@param connector VKConnector instance that sends notifications 
@param error error description 
*/ 
- (void) VKConnector:(VKConnector *)connector 
applicationWasDeleted:(NSError *)error; 

@end 


/** The main purpose of this class is to process user authorization and obtain 
access token which then will be used to perform requests from behalf of current 
user. 

Example: 

    [[VKConnector sharedInstance] startWithAppID:@"12345567" 
            permissions:@[@"wall"] 
            webView:webView 
            delegate:self]; 
*/ 
@interface VKConnector : NSObject <UIWebViewDelegate> 

/** 
@name Properties 
*/ 
/** Delegate 
*/ 
@property (nonatomic, weak, readonly) id <VKConnectorDelegate> delegate; 

/** Application's unique identifier 
*/ 
@property (nonatomic, strong, readonly) NSString *appID; 

/** Permissions 
*/ 
@property (nonatomic, strong, readonly) NSArray *permissions; 

/** 
@name Class methods 
*/ 
/** Returns shared instances of VKConnector class. 
*/ 
+ (id)sharedInstance; 

/** 
@name User authorization 
*/ 
/** Starts user authorization process. 

@param appID application's unique identifier 
@param permissions array of permissions (wall, friends, audio, video etc) 
@param webView UIWebView which will be used to display VK authorization page 
@param delegate delegate which will receive notifications 
*/ 
- (void)startWithAppID:(NSString *)appID 
      permissons:(NSArray *)permissions 
       webView:(UIWebView *)webView 
       delegate:(id <VKConnectorDelegate>)delegate; 

/** 
@name Cookies 
*/ 
/** Removes all cookies which were obtained after user has authorized VK 
application. This method is used to log out current user. 
*/ 
- (void)clearCookies; 

@end 

ho cercato di dividere file di intestazione VKConnector in due - classe VKConnector e VKConnectorDelegate, ma che non ha funzionato.

Cosa sto sbagliando?

+0

Hai importato le intestazioni necessarie (VkontakteSDK.h) nell'intestazione del bridging rapido? –

+0

Controlla l'intestazione del bridging. – CW0007007

+0

@Anil, sì, ho importato VkontakteSDK.h ma non ha funzionato, dopo che ho provato a importare tutti i file header che sono stati importati nel file di intestazione VkontakteSDK.h - niente ... – AndrewShmig

risposta

11

Il nome della propria funzione delegato è VKConnector e si dispone anche di una classe denominata VKConnector. Questo è il tuo conflitto. In Objective C il tuo metodo delegato è VKConnector:withBool: ma in Swift è semplicemente VKConnector e conBool non fa parte del nome.

Se si seguono i modelli di cacao, il vostro metodo delegato dovrebbe essere chiamato - (void) connector:(VKConnector *)connector withBool:(BOOL)boolean;

+0

ma non sto usando nessun altro framework eccetto UIKit e Foundation.Perché non funziona nel progetto ObjC, ma non nel progetto Swift? – AndrewShmig

+0

Vedere la risposta aggiornata. –

+0

ok, assumiamo che io non Ho dei codici sorgente di qualche libreria, come posso usare il codice ObjC scritto come ti ho mostrato (nel progetto di test e nell'SDK) nel progetto Swift? Grazie per il tuo aiuto, ha davvero senso. – AndrewShmig

2

XCode ha creato il file di intestazione di bridging o l'hai creato tu stesso?

Se è stato creato il file di intestazione colmare da soli, assicurarsi che costruiscono le impostazioni di puntare al file:

enter image description here

+0

Per favore, rileggi la mia domanda. Ci sono due link: da doc e da SO, e sicuramente ho aggiunto quell'impostazione nel mio progetto (da me stesso e anche da XCode) – AndrewShmig

+0

Mi hai ricordato che ho bisogno di aggiungere un'importazione al mio file di bridge - risolto :) – OhadM

1

L'errore "tipo non dichiarato" in un progetto misto è quasi sempre risolto come ho spiegato qui:

https://stackoverflow.com/a/24216718/341994

in sostanza, ovunque si sta importando il file di intestazione "...-Swift.h" generato automaticamente nel codice Objective-C, è sarà necessario importare "VKConnector.h" in quel file, in precedenza nell'elenco delle importazioni.

Questo è controintuitivo e fastidioso, ma risolve il problema, ed infatti è effettivamente documentato se si guarda molto da vicino.

+0

grazie , ma non funziona :(Ho anche creato questo argomento sul forum di Apple Dev: https://devforums.apple.com/message/1002447 e progetto di test (https://yadi.sk/d/QxPhrnysWFDGt) dove si può vedere che non funziona – AndrewShmig

1

Se aiuta nessuno, il nostro progetto di questo problema è stata causata perché abbiamo avuto un colpo di testa ponte sul bersaglio principale del progetto e un colpo di testa ponte su un obiettivo di estensione.

Il nostro obiettivo di estensione utilizzava una classe definita nel nostro progetto principale. Questa classe è stata definita all'interno dell'intestazione del bridging dell'estensione e funzionava per la maggior parte delle nostre classi.

Tuttavia, quando abbiamo assegnato l'appartenenza di destinazione di una delle nostre classi all'obiettivo principale del progetto, stavamo ottenendo questo errore in quel singolo file. La correzione era di garantire che i file utilizzati fossero in entrambi i file di intestazione del bridging.

+0

Ho la stessa situazione, due obiettivi e cerco di importare il mio progetto Objective-C in un altro target che è classi Swift. puoi spiegarlo di più, forse risolverà il mio problema .. –

Problemi correlati