Java クラスを Objective C (cradle プラグインを使用した J2Objc) に変換しています。シンプルな Android アプリと単体テストは問題なく動作します。同じ単純な Objective C iOS アプリも完全に機能します。ただし、Swift プロジェクトで同様のコードを記述しようとすると、インスタンス変数にアクセスしたり、メソッドを検索したりできません。これは私にとって比較的新しいことなので、基本的なものが欠けている可能性があります。
Objective C のコードは次のとおりです。完全に動作します。
SHRRefreshAppointments *mTest = [[SHRRefreshAppointments alloc] initWithId:nil withBoolean:true];
[mTest run];
SHREventListResp *mResp = [SHREventListResp parseFromWithByteArray:mTest->mResponseData_];
NSLog(@"%@", mResp.description);
Swift の同じコード - Objective C ですぐに利用できるインスタンス変数 mResponseData が見つかりません:
let mTest : SHRRefreshAppointments = SHRRefreshAppointments(id: nil, withBoolean: true)
mTest.run()
var mResp : SHREventListResp = SHREventListResp.parseFromWithByteArray(mTest.)
ブリッジング ヘッダーの内容は次のとおりです。
#include "JreEmulation.h"
#include "J2ObjC_header.h"
#import "com/gcatconsult/shared/remote/AppConstants.h"
#import "com/gcatconsult/shared/remote/AppUtils.h"
#import "com/gcatconsult/shared/messages/nano/Resp.h"
#import "com/gcatconsult/shared/messages/nano//Req.h"
#import "com/gcatconsult/shared/messages/nano/EventListResp.h"
#import "com/gcatconsult/shared/messages/nano/EventListReq.h"
#import "com/gcatconsult/shared/messages/nano/Event.h"
#import "com/gcatconsult/shared/remote/RefreshAppointments.h"
#import "com/gcatconsult/shared/remote/NetworkBase.h"
SHRRefreshAppointments ヘッダー:
//
// Generated by the J2ObjC translator. DO NOT EDIT!
// source: /Users/gabrielchoza/AndroidStudioProjects/GcatMobile/shared/src/main/java/com/gcatconsult/shared/remote/RefreshAppointments.java
//
#include "J2ObjC_header.h"
#pragma push_macro("INCLUDE_ALL_ComGcatconsultSharedRemoteRefreshAppointments")
#ifdef RESTRICT_ComGcatconsultSharedRemoteRefreshAppointments
#define INCLUDE_ALL_ComGcatconsultSharedRemoteRefreshAppointments 0
#else
#define INCLUDE_ALL_ComGcatconsultSharedRemoteRefreshAppointments 1
#endif
#undef RESTRICT_ComGcatconsultSharedRemoteRefreshAppointments
#if !defined (SHRRefreshAppointments_) && (INCLUDE_ALL_ComGcatconsultSharedRemoteRefreshAppointments || defined(INCLUDE_SHRRefreshAppointments))
#define SHRRefreshAppointments_
#define RESTRICT_ComGcatconsultSharedRemoteNetworkBase 1
#define INCLUDE_SHRNetworkBase 1
#include "com/gcatconsult/shared/remote/NetworkBase.h"
#define RESTRICT_JavaLangRunnable 1
#define INCLUDE_JavaLangRunnable 1
#include "java/lang/Runnable.h"
@interface SHRRefreshAppointments : SHRNetworkBase < JavaLangRunnable >
#pragma mark Public
- (instancetype)initWithId:(id)requestData
withBoolean:(jboolean)asyncCall;
#pragma mark Protected
- (void)postProcessExcecute;
@end
J2OBJC_EMPTY_STATIC_INIT(SHRRefreshAppointments)
FOUNDATION_EXPORT void SHRRefreshAppointments_initWithId_withBoolean_(SHRRefreshAppointments *self, id requestData, jboolean asyncCall);
FOUNDATION_EXPORT SHRRefreshAppointments *new_SHRRefreshAppointments_initWithId_withBoolean_(id requestData, jboolean asyncCall) NS_RETURNS_RETAINED;
FOUNDATION_EXPORT SHRRefreshAppointments *create_SHRRefreshAppointments_initWithId_withBoolean_(id requestData, jboolean asyncCall);
J2OBJC_TYPE_LITERAL_HEADER(SHRRefreshAppointments)
@compatibility_alias ComGcatconsultSharedRemoteRefreshAppointments SHRRefreshAppointments;
#endif
#pragma pop_macro("INCLUDE_ALL_ComGcatconsultSharedRemoteRefreshAppointments")
SHRNetworkBase スーパークラス:
//
// Generated by the J2ObjC translator. DO NOT EDIT!
// source: /Users/gabrielchoza/AndroidStudioProjects/GcatMobile/shared/src/main/java/com/gcatconsult/shared/remote/NetworkBase.java
//
#include "J2ObjC_header.h"
#pragma push_macro("INCLUDE_ALL_ComGcatconsultSharedRemoteNetworkBase")
#ifdef RESTRICT_ComGcatconsultSharedRemoteNetworkBase
#define INCLUDE_ALL_ComGcatconsultSharedRemoteNetworkBase 0
#else
#define INCLUDE_ALL_ComGcatconsultSharedRemoteNetworkBase 1
#endif
#undef RESTRICT_ComGcatconsultSharedRemoteNetworkBase
#if !defined (SHRNetworkBase_) && (INCLUDE_ALL_ComGcatconsultSharedRemoteNetworkBase || defined(INCLUDE_SHRNetworkBase))
#define SHRNetworkBase_
#define RESTRICT_JavaLangRunnable 1
#define INCLUDE_JavaLangRunnable 1
#include "java/lang/Runnable.h"
@class IOSByteArray;
@class JavaLangInteger;
@interface SHRNetworkBase : NSObject < JavaLangRunnable > {
@public
NSString *mGetPatientPath_;
NSString *mStringURL_;
IOSByteArray *mRequestData_;
IOSByteArray *mResponseData_;
jboolean mShouldCompress_;
jint mCurrentCall_;
jboolean mAsyncCall_;
}
#pragma mark Public
- (instancetype)initWithNSString:(NSString *)callPath
withBoolean:(jboolean)shouldCompress
withJavaLangInteger:(JavaLangInteger *)currentCall
withBoolean:(jboolean)async;
- (void)run;
#pragma mark Protected
- (void)postProcessExcecute;
- (id)sendAsyncServerRequestWithNSString:(NSString *)stringURL
withId:(id)requestData
withBoolean:(jboolean)shouldCompress
withJavaLangInteger:(JavaLangInteger *)currentCall;
@end
J2OBJC_EMPTY_STATIC_INIT(SHRNetworkBase)
J2OBJC_FIELD_SETTER(SHRNetworkBase, mGetPatientPath_, NSString *)
J2OBJC_FIELD_SETTER(SHRNetworkBase, mStringURL_, NSString *)
J2OBJC_FIELD_SETTER(SHRNetworkBase, mRequestData_, IOSByteArray *)
J2OBJC_FIELD_SETTER(SHRNetworkBase, mResponseData_, IOSByteArray *)
FOUNDATION_EXPORT void SHRNetworkBase_initWithNSString_withBoolean_withJavaLangInteger_withBoolean_(SHRNetworkBase *self, NSString *callPath, jboolean shouldCompress, JavaLangInteger *currentCall, jboolean async);
FOUNDATION_EXPORT SHRNetworkBase *new_SHRNetworkBase_initWithNSString_withBoolean_withJavaLangInteger_withBoolean_(NSString *callPath, jboolean shouldCompress, JavaLangInteger *currentCall, jboolean async) NS_RETURNS_RETAINED;
FOUNDATION_EXPORT SHRNetworkBase *create_SHRNetworkBase_initWithNSString_withBoolean_withJavaLangInteger_withBoolean_(NSString *callPath, jboolean shouldCompress, JavaLangInteger *currentCall, jboolean async);
J2OBJC_TYPE_LITERAL_HEADER(SHRNetworkBase)
@compatibility_alias ComGcatconsultSharedRemoteNetworkBase SHRNetworkBase;
#endif
#pragma pop_macro("INCLUDE_ALL_ComGcatconsultSharedRemoteNetworkBase")
どんな助けでも大歓迎です。