Skip to content

Commit

Permalink
Add Objective-C version
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylEnkidu committed Nov 5, 2024
1 parent 299de31 commit ec7848e
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 6 deletions.
36 changes: 36 additions & 0 deletions Firestore/Source/API/FIRInterface.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

#import "Firestore/Source/Public/FirebaseFirestore/FIRInterface.h"

#import "Firestore/core/src/api/used_by_objective_c.h"
#include "Firestore/core/src/util/string_apple.h"

using firebase::firestore::util::MakeString;

NS_ASSUME_NONNULL_BEGIN

@implementation FIRInterface

+ (void)print:(NSString *)content {
CppInterfaceCalledByObjectiveC::print(MakeString(content));
}

@end

NS_ASSUME_NONNULL_END
29 changes: 29 additions & 0 deletions Firestore/Source/Public/FirebaseFirestore/FIRInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface FIRInterface : NSObject

#pragma mark - Create Filter

+ (void)print:(NSString *)content;

@end

NS_ASSUME_NONNULL_END
4 changes: 2 additions & 2 deletions Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
@_exported import FirebaseFirestoreCpp
#endif // SWIFT_PACKAGE

public class SwiftCppWrapper {
public class SwiftCallingCpp {
public init(_ value: String) {
_ = UsedBySwift(std.string(value))
CppInterfaceCalledBySwift.print(std.string(value))

Check failure on line 23 in Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift

View workflow job for this annotation

GitHub Actions / platforms (catalyst)

no exact matches in call to initializer

Check failure on line 23 in Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift

View workflow job for this annotation

GitHub Actions / platforms (catalyst)

no exact matches in call to initializer
}
}
22 changes: 22 additions & 0 deletions Firestore/core/src/api/used_by_objective_c.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "used_by_objective_c.h"
#include <iostream>

void CppInterfaceCalledByObjectiveC::print(std::string content) {
std::cout << "C++ function runs with value: " << content << std::endl;
}
27 changes: 27 additions & 0 deletions Firestore/core/src/api/used_by_objective_c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FIREBASE_USED_BY_SWIFT_H
#define FIREBASE_USED_BY_SWIFT_H

#include <string>

class CppInterfaceCalledByObjectiveC {
public:
static void print(std::string content);
};

#endif // FIREBASE_USED_BY_SWIFT_H
4 changes: 2 additions & 2 deletions Firestore/core/swift/include/used_by_swift.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

#include <string>

Check failure on line 20 in Firestore/core/swift/include/used_by_swift.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'string' file not found

Check failure on line 20 in Firestore/core/swift/include/used_by_swift.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'string' file not found

Check failure on line 20 in Firestore/core/swift/include/used_by_swift.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'string' file not found

Check failure on line 20 in Firestore/core/swift/include/used_by_swift.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'string' file not found

Check failure on line 20 in Firestore/core/swift/include/used_by_swift.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'string' file not found

class UsedBySwift {
class CppInterfaceCalledBySwift {
public:
explicit UsedBySwift(std::string content);
static void print(std::string content);
};

#endif // FIREBASE_USED_BY_SWIFT_H
4 changes: 2 additions & 2 deletions Firestore/core/swift/src/used_by_swift.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
#include "../include/used_by_swift.h"
#include <iostream>

UsedBySwift::UsedBySwift(std::string content) {
std::cout << "ctor runs with value: " << content << std::endl;
void CppInterfaceCalledBySwift::print(std::string content) {
std::cout << "C++ function runs with value: " << content << std::endl;
}

0 comments on commit ec7848e

Please sign in to comment.