Skip to content

Commit ec7848e

Browse files
committed
Add Objective-C version
1 parent 299de31 commit ec7848e

File tree

7 files changed

+120
-6
lines changed

7 files changed

+120
-6
lines changed

Firestore/Source/API/FIRInterface.mm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
#import "Firestore/Source/Public/FirebaseFirestore/FIRInterface.h"
20+
21+
#import "Firestore/core/src/api/used_by_objective_c.h"
22+
#include "Firestore/core/src/util/string_apple.h"
23+
24+
using firebase::firestore::util::MakeString;
25+
26+
NS_ASSUME_NONNULL_BEGIN
27+
28+
@implementation FIRInterface
29+
30+
+ (void)print:(NSString *)content {
31+
CppInterfaceCalledByObjectiveC::print(MakeString(content));
32+
}
33+
34+
@end
35+
36+
NS_ASSUME_NONNULL_END
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
NS_ASSUME_NONNULL_BEGIN
20+
21+
@interface FIRInterface : NSObject
22+
23+
#pragma mark - Create Filter
24+
25+
+ (void)print:(NSString *)content;
26+
27+
@end
28+
29+
NS_ASSUME_NONNULL_END

Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
@_exported import FirebaseFirestoreCpp
1919
#endif // SWIFT_PACKAGE
2020

21-
public class SwiftCppWrapper {
21+
public class SwiftCallingCpp {
2222
public init(_ value: String) {
23-
_ = UsedBySwift(std.string(value))
23+
CppInterfaceCalledBySwift.print(std.string(value))
2424
}
2525
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "used_by_objective_c.h"
18+
#include <iostream>
19+
20+
void CppInterfaceCalledByObjectiveC::print(std::string content) {
21+
std::cout << "C++ function runs with value: " << content << std::endl;
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FIREBASE_USED_BY_SWIFT_H
18+
#define FIREBASE_USED_BY_SWIFT_H
19+
20+
#include <string>
21+
22+
class CppInterfaceCalledByObjectiveC {
23+
public:
24+
static void print(std::string content);
25+
};
26+
27+
#endif // FIREBASE_USED_BY_SWIFT_H

Firestore/core/swift/include/used_by_swift.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
#include <string>
2121

22-
class UsedBySwift {
22+
class CppInterfaceCalledBySwift {
2323
public:
24-
explicit UsedBySwift(std::string content);
24+
static void print(std::string content);
2525
};
2626

2727
#endif // FIREBASE_USED_BY_SWIFT_H

Firestore/core/swift/src/used_by_swift.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
#include "../include/used_by_swift.h"
1818
#include <iostream>
1919

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

0 commit comments

Comments
 (0)