2014-09-30 34 views
2

我正在Swift中開發一個框架,並且在嘗試在Obj-C文件中使用我的.swift類時遇到了麻煩。Swift導入模塊文件仍然導致未聲明的標識符編譯器錯誤

  • 我證實,我輸入正確的模塊文件:「SDK-Swift.h」
  • 創建了自己的-Swift.h模塊。我使用的IDE
  • 沒有關於我的任何種類的任何命名約定衝突提供了一個
  • Product Module Name確實SDK
  • GGNetworking從NSObject繼承,因此包括必要的@objc

即使我已經根據Apple的文檔完成了所有必需的步驟,但我仍然得到編譯器錯誤:Use of undeclared identifier 'GGNetworking'

實施和項目本身不可能更簡單。

#import <UIKit/UIKit.h> 
#import "SDK-Swift.h" 

@interface GGHomie : NSObject 

@end 

@implementation GGHomie 

- (id)init 
{ 
    self = [super init]; 
    if (self) 
    { 
     GGNetworking *network = [[GGNetworking alloc] init]; // <-- Compiler error here 
    } 

    return self; 
} 

@end 

我知道我不是唯一一個在SO摔跤Obj-C的Swift代碼;)任何人都可以衡量這個嗎?

更新

SDK-Swift.h

// Generated by Swift version 1.0 (swift-600.0.51.4) 

#if defined(__has_include) && __has_include(<swift/objc-prologue.h>) 
# include <swift/objc-prologue.h> 
#endif 

#include <objc/NSObject.h> 
#include <stdint.h> 
#include <stddef.h> 
#include <stdbool.h> 

#if defined(__has_include) && __has_include(<uchar.h>) 
# include <uchar.h> 
#elif __cplusplus < 201103L 
typedef uint_least16_t char16_t; 
typedef uint_least32_t char32_t; 
#endif 
#if !defined(SWIFT_PASTE) 
# define SWIFT_PASTE_HELPER(x, y) x##y 
# define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y) 
#endif 
#if !defined(SWIFT_METATYPE) 
# define SWIFT_METATYPE(X) Class 
#endif 

#if defined(__has_attribute) && __has_attribute(objc_runtime_name) 
# define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X))) 
#else 
# define SWIFT_RUNTIME_NAME(X) 
#endif 
#if !defined(SWIFT_CLASS_EXTRA) 
# define SWIFT_CLASS_EXTRA 
#endif 
#if !defined(SWIFT_PROTOCOL_EXTRA) 
# define SWIFT_PROTOCOL_EXTRA 
#endif 
#if !defined(SWIFT_CLASS) 
# if defined(__has_attribute) && __has_attribute(objc_subclassing_restricted) 
# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA 
# else 
# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA 
# endif 
#endif 

#if !defined(SWIFT_PROTOCOL) 
# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA 
#endif 

#if !defined(SWIFT_EXTENSION) 
# define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__) 
#endif 

#if !defined(OBJC_DESIGNATED_INITIALIZER) 
# if defined(__has_attribute) && __has_attribute(objc_designated_initializer) 
# define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer)) 
# else 
# define OBJC_DESIGNATED_INITIALIZER 
# endif 
#endif 
#pragma clang diagnostic push 
#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch" 

#if defined(__has_feature) && __has_feature(modules) 
#endif 

#pragma clang diagnostic pop 

GGNetworking.swift

import UIKit 
import Alamofire 

public class GGNetworking: NSObject { 

    public class var baseUrl:NSString! { 
     get { 
      return "http://www.google.com/mobile/api/v1/" 
     } 
    } 

    public class func getInImageAd(url:GGInImageAdUrl!, completionHandler:(AnyObject?, NSError?) -> Void) { 
     Alamofire.request(.GET, url.absoluteString!).response { (request, response, data, error) in 
      if (error != nil) { 
       println("An error occurred while getting an in-image ad (\(url.absoluteString)): \(error)") 
       completionHandler(nil, error) 
      } else { 
       completionHandler(data, nil) 
      } 
     } 
    } 

    public class func getInScreenAd(url:GGInScreenAdUrl!, completionHandler:(AnyObject?, NSError?) -> Void) { 
     Alamofire.request(.GET, url.absoluteString!).response { (request, response, data, error) in 
      if (error != nil) { 
       println("An error occurred while getting an in-screen ad (\(url.absoluteString)): \(error)") 
       completionHandler(nil, error) 
      } else { 
       completionHandler(data, nil) 
      } 
     } 
    } 
} 

最後,我的構建階段設置的截圖: enter image description here

回答

3
  • GGNetworking非私人(即internal(默認)或public
  • GGNetworking是否有非私人初始值設定項?
  • 初始化程序ObjC是否兼容?即不使用ObjC中不可用的參數類型。
  • 你的SDK-Swift.h的內容是什麼? Xcode實際上在您的DerivedData文件夾(~/Library/Developer/Xcode/DerivedData/...)中的某個位置生成此文件。讓Finder搜索它。
  • 粘貼GGNetworking類的相關代碼也可以幫助我們。
  • Swift文件是實際編譯的嗎?即你可以使用其他Swift文件嗎?

更多信息後提供更新時間:

是否加入public override init() { super.init() }GGNetworking解決這一問題?

+0

已更新回答:) – fluidsonic 2014-09-30 23:43:31

+0

婊子的兒子,就是這樣。謝謝! – jakenberg 2014-09-30 23:46:32

+0

這應該像50+點!公共初始化程序是我的。 – user1366265 2016-02-03 17:45:54

相關問題