Reputation: 2113
I am developing a framework in Swift, and I've run into trouble while trying to use my .swift classes inside of Obj-C files.
Product Module Name
is indeed SDKNSObject
, therefore including the necessary @objc
I am still given the compiler error: Use of undeclared identifier 'GGNetworking'
even though I have done all of the steps necessary according to Apple's documentation.
The implementation and project itself couldn't be more simple.
#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
I know I'm not the only one on SO wrestling Obj-C to Swift code ;) Can anyone weigh in on this?
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)
}
}
}
}
Finally, a screenshot of my Build Phases setup:
Upvotes: 2
Views: 5020
Reputation: 4676
GGNetworking
non-private (i.e. internal
(default) or public
?GGNetworking
have a non-private initializer?SDK-Swift.h
? Xcode actually generates this file somewhere in your DerivedData
folder (~/Library/Developer/Xcode/DerivedData/...
). Just let Finder search for it.GGNetworking
class could also help us.Updated after more info provided:
Does adding public override init() { super.init() }
to GGNetworking
solve the issue?
Upvotes: 3