Deeya Sethi

1619081430

Most Important Techniques to Play Rummy Online

The guidelines of rummy are unpredictable, yet sensible. On the off chance that you are new to Rummy or in the event that you need to review your insight, everything is conveniently clarified here. To know more exciting tricks you must Play ultimate rummy

The point in Rummy is to play your cards as merges. A round closes when a player disposes of their last card onto the disposed of the heap. Presently the scores are resolved: Each player summarizes the scores of each card left in their grasp and records them as punishment focuses. The victor acquires the amount of everyone’s negative scores as certain focuses. The following round starts until the most extreme number of rounds is reached or one of the players hits 500 negative focuses. The player with the most noteworthy score is the champ of the table!

The Deck: 2×52 Cards and 6 Jokers

Rummy is played with 110 cards: 104 = 2 x 52 French playing a card game + 6 Jokers.

Each card holds a specific score that matters for playing the primary merge (at any rate three cards with a base score of 30 focuses altogether) just as for deciding the scores of every player toward the finish of around.

The pip cards score focuses as indicated by their portrayed number – from two to ten.

The face-or picture cards (Jack, Queen, King) each score 10 focuses.

The Ace scores one moment that merged in a grouping "Pro 2-3-4… " yet eleven focuses when it follows a King, for instance, “Sovereign King-Ace”. An Ace in the hand scores eleven focuses too.

The Joker has differing values: When merging it assumes the worth of the card it replaces. A joker in the hands scores 20 focuses. To know more succession tricks you must play ultimate rummy.

Rearranging, managing, and round it goes

Right rearranging and managing are none of your concerns at the virtual tables at the KhelPlay Rummy: A calculation deals with it. Every player gets 13 cards. One card is uncovered as the disposal of the heap. The extra cards are the stock.

The game goes clockwise. The principal player, arbitrarily picked, checks their cards and plays their first turn:

They should draw a card from the stock or the disposal of the heap.

They can play their first merge, if conceivable, and play further merges thereafter.

They should dispose of one card from their hand onto the disposal of the heap.

Presently it’s the following player’s turn:

They draw a card from the stock or get the card just disposed of by the past player.

They can play their first merge, if conceivable, and proceed with playing merges, laying off cards by adding them to existing merges, and trading Jokers.

At long last, they dispose of one card.

Merges must be played or added to during the own turn. Potential merges are clarified in the accompanying area.

Playing merges: Sets and Sequences

Rummy knows two kinds of merges – sets and groupings.

Sets, or gatherings, comprise of at any rate three cards of a similar position. Sets can be made out of a wide range of cards – pip cards (2 to 10), face cards (Jack, Queen, King), and Aces. Each suit (Clubs, Spades, Diamonds, and Hearts) can just show up once, so a limit of four cards for every set is conceivable.

Successions, or runs, comprise of at least three resulting cards of one suit. The accompanying request is in power: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace. The Ace has two potential positions however each card, including the Ace, can just show up once in a succession. A limit of 13 cards for each arrangement is conceivable. This is particularly pertinent when playing with the custom standard “Cyclic Laying”. To learn more sequences tricks you must play ultimate rummy.

The main merge should satisfy extra necessities: Each player’s first mix of cards during a round should score at any rate 30 focuses. In any event, three cards should be played. This can be accomplished by playing a bunch of three 10s, Jacks, Queens, Kings, or Aces of various suits. Playing arrangements is likewise a choice, for instance, “10-Jack-Queen-King”, “Jack-Queen-King-Ace” or “7-8-9-10-Jack”.

HEADS UP: An Ace in a grouping scores eleven focuses when following a King, for instance, “Jack-Queen-King-Ace”, yet just one moment that followed by pips, for instance, "Pro 2-3-… "

Subsequent to playing the primary merge the player can utilize their chance to play quite a few merges conceivable. Cards can likewise be added to existing merges, alluded to as laying off. Subtleties follow further underneath.

The Joker enters the game

While merging, the happy entertainer gets an opportunity: Jokers supplant a card missing in a merge.

Model for a Sequence: “Jack-Queen-Joker-Ace” => The Joker replaces the King.

Model for a Set: “4 of Clubs-4 of Spades-Joker” => The Joker replaces the third 4 (both of Diamonds or Hearts).

The Joker completely emulates the supplanted card, including the score. Supplanting a King the Joker scores ten focuses, supplanting a 4 it scores four focuses. Remember this when creating your first merge.

It is feasible to play two sequential Jokers on the off chance that they don’t dwarf the regular cards and the Jokers’ position is self-evident.

A bunch of four is conceivable: “3 of Hearts-3 of Diamonds-Joker-Joker” => The Jokers supplant 3 of Clubs and 3 of Spades.

A succession including two Jokers functions too. For instance: “9 of Hearts-Joker-Joker-Queen of Hearts” => The Jokers supplant 10 of Hearts and Jack of Hearts.

Laying off

Subsequent to playing the principal merge, a player can add at least one cards from their hand to any current merges. In the event that there is a bunch of three Kings, the fourth King can be added to this set. Moreover, an arrangement can be expanded. For instance, “7-8-9-10” can be stretched out by the 6 or the Jack of the coordinating with suit.

Trading Jokers

During their turn, a player can likewise eliminate Jokers from existing merges, on the off chance that they can supplant it with the missing card. The acquired Joker should be merged during a similar turn!

Rummy!

At the point when a player merged, traded, or laid off the entirety of their cards and disposed of the last one onto the dispose of the heap, they shout: Rummy! They won the round.

Different players presently each summarize the scores of the cards left in their grasp. The scores are determined as at first portrayed: The score of the pip cards coordinates with the number portrayed on them, face cards score ten, the Ace scores eleven and the Joker tops them all with 20 focuses. Every player gets their hand’s score as punishment focuses. Be that as it may, the victor acquires the amount, everything being equal. To learn the tricks you must do the classic rummy download.

Furthermore, since everything is clear – don’t hesitate to feel free to give it a shot!

रम्मी के दिशा-निर्देश अप्रत्याशित हैं, फिर भी समझदार हैं । बंद मौके पर कि आप रम्मी के लिए नए हैं या इस घटना में कि आपको अपनी अंतर्दृष्टि की समीक्षा करने की आवश्यकता है, सब कुछ आसानी से यहां स्पष्ट किया गया है। अधिक रोमांचक तरकीबें जानने के लिए आपको [क्लासिक रम्मी डाउनलोड] (https://www.khelplayrummy.com/classic-रम्मी “क्लासिक रमी डाउनलोड”) करना होगा।

रम्मी में बात विली के रूप में अपने पत्ते खेलने के लिए है। एक दौर बंद हो जाता है जब एक खिलाड़ी ढेर के निपटान पर अपने पिछले कार्ड का निपटान करता है। वर्तमान में स्कोर हल कर रहे हैं: प्रत्येक खिलाड़ी प्रत्येक कार्ड के स्कोर को अपनी समझ में छोड़ दिया और सजा केंद्रित के रूप में उन्हें रिकॉर्ड प्रस्तुत करता है। विक्टर कुछ केंद्रित के रूप में हर किसी के नकारात्मक स्कोर की राशि प्राप्त करता है । निम्नलिखित दौर तब तक शुरू होता है जब तक कि सबसे चरम संख्या में राउंड नहीं पहुंच जाते या खिलाड़ियों में से एक 500 नकारात्मक केंद्रित हो जाता है। सबसे उल्लेखनीय स्कोर के साथ खिलाड़ी तालिका का विजेता है!

डेक: 2×52 कार्ड और 6 जोकर

**रम्मी ** 110 कार्ड के साथ खेला जाता है: 104 = 2 x 52 फ्रेंच एक कार्ड गेम + 6 जोकर खेलते हैं।

प्रत्येक कार्ड एक विशिष्ट स्कोर है कि प्राथमिक मर्ज खेलने के लिए मायने रखती है (30 के एक आधार स्कोर के साथ किसी भी दर तीन कार्ड पर पूरी तरह से केंद्रित) बस के रूप में चारों ओर के खत्म होने की ओर हर खिलाड़ी के स्कोर तय करने के लिए ।

पिप कार्ड स्कोर उनके चित्रित संख्या द्वारा इंगित के रूप में केंद्रित है - दो से दस तक।

चेहरा या चित्र कार्ड (जैक, रानी, राजा) प्रत्येक स्कोर 10 केंद्रित है ।

ऐस स्कोर एक पल है कि एक समूह में विलय "प्रो 2-3-4… । "अभी तक ग्यारह केंद्रित है जब यह एक राजा के बाद, उदाहरण के लिए, “प्रभु राजा-इक्का” । हाथ स्कोर ग्यारह में एक इक्का भी केंद्रित है ।

जोकर मूल्यों अलग है: जब विलय यह कार्ड यह जगह के लायक मान लिया । हाथों में एक जोकर स्कोर 20 केंद्रित है । अधिक उत्तराधिकार ट्रिक्स जानने के लिए आपको क्लासिक रम्मी डाउनलोड करना होगा

    • पुनर्व्यवस्था, प्रबंधन, और दौर यह चला जाता है **

सही उलटफेर और प्रबंधन खेलप्ले रम्मी में आभासी तालिकाओं में आपकी कोई भी चिंता नहीं है: एक गणना इसके साथ संबंधित है। हर खिलाड़ी को 13 कार्ड मिलते हैं। ढेर के निपटान के रूप में एक कार्ड खुला है। अतिरिक्त कार्ड स्टॉक हैं।

खेल दक्षिणावर्त चला जाता है। प्रमुख खिलाड़ी, मनमाने ढंग से उठाया, उनके कार्ड की जांच करता है और अपनी पहली बारी निभाता है:

उन्हें स्टॉक या ढेर के निपटान से एक कार्ड निकालना चाहिए।

वे अपना पहला मर्ज खेल सकते हैं, यदि बोधगम्य है, और उसके बाद आगे विलीन हो जाता है।

उन्हें ढेर के निपटान पर अपने हाथ से एक कार्ड का निपटान करना चाहिए।

वर्तमान में यह निम्नलिखित खिलाड़ी की बारी है:

वे स्टॉक से एक कार्ड आकर्षित या कार्ड सिर्फ पिछले खिलाड़ी द्वारा निपटाया मिलता है ।

वे अपना पहला मर्ज खेल सकते हैं, यदि बोधगम्य, और विलय खेलने के साथ आगे बढ़ें, उन्हें मौजूदा मर्ज में जोड़कर कार्ड बिछाने, और जोकर व्यापार कर सकते हैं।

पिछले कुछ समय में, वे एक कार्ड का निपटान करते हैं।

मर्ज खेला जाना चाहिए या अपनी बारी के दौरान जोड़ा जाना चाहिए। संभावित मर्ज साथ क्षेत्र में स्पष्ट किए जाते हैं।

** बजाना विलीन हो जाता है: सेट और दृश्यों **

रम्मी दो तरह के मर्ज जानते हैं- सेट और ग्रुपिंग।

** सेट, या समारोहों **, एक समान स्थिति के किसी भी दर तीन कार्ड पर शामिल हैं । सेट कार्ड की एक विस्तृत श्रृंखला से बाहर किया जा सकता है - रंज कार्ड (2 से 10), चेहरा कार्ड (जैक, रानी, राजा), और इक्के। प्रत्येक सूट (क्लब, हुकुम, हीरे, और दिल) सिर्फ एक बार दिखा सकते हैं, तो हर सेट के लिए चार कार्ड की एक सीमा बोधगम्य है ।

    • उत्तराधिकार **, या रन, एक सूट के कम से कम तीन परिणामस्वरूप कार्ड शामिल हैं। साथ अनुरोध सत्ता में है: ऐस, 2, 3, 4, 5, 6, 7, 8, 9, 10, जैक, रानी, राजा, ऐस । ऐस दो संभावित पदों पर है, लेकिन इक्का सहित प्रत्येक कार्ड, बस एक उत्तराधिकार में एक बार दिखा सकते हैं । प्रत्येक व्यवस्था के लिए 13 कार्ड की एक सीमा बोधगम्य है। कस्टम मानक “चक्रीय बिछाने” के साथ खेलते समय यह विशेष रूप से प्रासंगिक है। अधिक दृश्यों की ट्रिक्स सीखने के लिए आपको क्लासिक रम्मी डाउनलोड करना होगा।

मुख्य मर्ज अतिरिक्त आवश्यकताओं को संतुष्ट करना चाहिए: प्रत्येक खिलाड़ी के एक दौर के दौरान ताश के पत्तों का पहला मिश्रण किसी भी दर 30 केंद्रित पर स्कोर करना चाहिए । किसी भी आयोजन में तीन पत्ते बजाने चाहिए। यह तीन 10s, जैक, क्वींस, किंग्स, या विभिन्न सूट के इक्के का एक गुच्छा खेलकर पूरा किया जा सकता है । खेल व्यवस्था इसी तरह एक विकल्प है, उदाहरण के लिए, “10-जैक-रानी-राजा”, “जैक-रानी-राजा-ऐस” या “7-8-9-10-जैक” ।

सिर ऊपर: एक समूह स्कोर ग्यारह में एक इक्का केंद्रित है जब एक राजा के बाद, उदाहरण के लिए, “जैक-रानी-राजा-ऐस”, अभी तक सिर्फ एक पल है कि pips के बाद, उदाहरण के लिए, "प्रो 2-3-… "

प्राथमिक मर्ज खेलने के बाद खिलाड़ी काफी कुछ बोधगम्य विलीन हो जाता है खेलने के लिए अपने मौका का उपयोग कर सकते हैं। कार्ड इसी तरह मौजूदा मर्ज में जोड़ा जा सकता है, बंद बिछाने के रूप में alluded । बारीकियों के नीचे आगे का पालन करें ।

**द जोकर खेल में प्रवेश करता है **

विलय करते समय, खुश मनोरंजन एक अवसर हो जाता है: जोकर एक मर्ज में लापता कार्ड हटाना ।

एक अनुक्रम के लिए मॉडल: “जैक-क्वीन-जोकर-ऐस” = > जोकर राजा की जगह लेगा।

एक सेट के लिए मॉडल: “हुकुम के क्लब-4 के 4-जोकर” = > जोकर तीसरे 4 (हीरे या दिल के दोनों) की जगह जाता है ।

What is GEEK

Buddha Community

Most Important Techniques to Play Rummy Online

Como Exportar Uma Função De C++ Para React Native

Hoje, continuo compartilhando minha experiência com o Módulo Nativo e C++.

Como veremos muitas bibliotecas C/C++ escrevendo para plataformas móveis, precisamos implementá-las em nosso aplicativo iOS ou React Native. É por isso que quero escrever um artigo sobre como exportar uma função de C++ para React Native, que é fácil de entender e economiza tempo para iniciantes. Vou começar com um novo aplicativo nativo de reação

1. Crie um novo aplicativo nativo de reação, abra seu terminal e execute

npx react-native init NativeModules

2. Abra o Xcode e navegue até NativeModules/ios/NativeModule.xcworkspace

3. Trabalhando no lado C++

Crie um novo arquivo C++ e nomeie-oCpp_to_RN.cpp

Quando criamos um novo arquivo C++, o Xcode criará um arquivo de cabeçalho Cpp_to_RN.hpp para nós

Primeiro, abra o arquivo “ Cpp_to_RN.hpp e crie uma classe que inclua uma função sem o corpo.

#ifndef Cpp_to_RN_hpp
#define Cpp_to_RN_hpp#include <stdio.h>
#include <string>class Cpp_to_RN {
public:
    std::string sayHello();
};#endif /* Cpp_to_RN_hpp */

Em seguida, abra o Cpp_to_RN.cpparquivo e escreva uma função simples “ sayHello()

#include "Cpp_to_RN.hpp"
std::string Cpp_to_RN::sayHello(){
    return "Hello from CPP";
}

4. Trabalhando no arquivo C++ de encapsulamento.

Para encapsular os arquivos C++ e exportá-los para o lado IOS (swift)

uma. Crie um arquivo Objective C e nomeie-oCpp_to_RN.m

Renomeie o Cpp_to_RN.m para Cpp_to_RN.mm

b. Abra o WrapCpp_to_RN.mm arquivo e escreva o conteúdo do corpo que envolverá a função sayHellodo arquivo C++.

#import <Foundation/Foundation.h>
#import "WrapCpp_to_RN.h"
#import "Cpp_to_RN.hpp"@implementation WrapCpp_to_RN- (NSString *) sayHello {
  Cpp_to_RN fromCPP;
    std::string helloWorldMessage = fromCPP.sayHello();
    return [NSString
            stringWithCString:helloWorldMessage.c_str()
            encoding:NSUTF8StringEncoding];
}
@end

c. Crie um arquivo de cabeçalho e nomeie-oWrapCpp_to_RN.h

Exporte a wrapSayHellofunção para o arquivo Swift

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

5. Trabalhando no lado iOS (Swift)

Para exportar a função C++ para React Native

uma. Crie um arquivo Swift e nomeie-oSendCpp_to_RN.swift

Observação: o Xcode nos pedirá para criar um NativeModules-Bridging-Header.harquivo para nós.

Crie uma classe SendCpp_to_RNe declare-a comoNSObject

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

Escreva uma função requiresMainQueueSetup()para evitar avisos quando executamos o aplicativo

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

Escreva uma função para envolver o WrapCpp_to_RN()fromWrapCpp_to_RN.mm

import Foundation@objc(SendCpp_to_RN)
class SendCpp_to_RN : NSObject {
    
  @objc static func requiresMainQueueSetup() -> Bool {
        return false
    }
  
  @objc func fromCpp(_ successCallback: RCTResponseSenderBlock) -> Void {
    successCallback([NSNull(), WrapCpp_to_RN().wrapSayHello() as Any])
    }}

b. Exporte uma função wrap no arquivo Swift para React Native

Crie um arquivo Objective C para exportar a classe Swift e sua função usandoCallback

#import <React/RCTBridgeModule.h>
#import <Foundation/Foundation.h>
#import "UIKit/UIKit.h"
@interface RCT_EXTERN_MODULE(SendCpp_to_RN, NSObject)RCT_EXTERN_METHOD(fromCpp:(RCTResponseSenderBlock)successCallback)@end

c. Conecte o Swift ao React Native, abra o NativeModules-Bridging-Header.h arquivo

#import <React/RCTBridgeModule.h>#import <React/RCTViewManager.h>#import "WrapCpp_to_RN.h"

6. Trabalhando no lado React Native

Chame a classe Swift e suas funções

import React from 'react';
import {StyleSheet, Text, View, NativeModules, Button} from 'react-native';const App = () => {
  const onPress = () => {
    const {SendCpp_to_RN} = NativeModules;
    SendCpp_to_RN.fromCpp((_err, res) => console.log(res));
  };
  return (
    <View style={styles.container}>
      <Text> Practice !</Text>
      <Button title="C++ to React Native" color="#841584" onPress={onPress} />
    </View>
  );
};
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});
export default App;

E pronto, basta executar o aplicativo

react-native run-ios

Ou apenas clique no botão “executar” no Xcode e veja o que fizemos.

Espero que meu artigo seja útil para você, obrigado pelo tempo de leitura.

 Fonte: https://betterprogramming.pub/native-modules-export-c-function-to-react-native-for-beginners-77e89934b210

#cpp #cplusplus #react 

坂本  篤司

坂本 篤司

1656981060

関数をC++からReactNativeにエクスポートする方法

今日も、ネイティブモジュールとC++での経験を共有し続けています。

多くのC/C ++ライブラリがモバイルプラットフォーム用に作成されているので、それらをiOSまたはReactNativeアプリケーションに実装する必要があります。そのため、関数をC++からReactNativeにエクスポートする方法についての記事を書きたいと思います。これは、理解しやすく、初心者の時間を節約できます。新しいreactネイティブアプリケーションから始めます

1.新しいreactネイティブアプリを作成し、ターミナルを開いて実行します

npx react-native init NativeModules

2. Xcodeを開き、NativeModules / ios/NativeModule.xcworkspaceに移動します

3.C++側での作業

新しいC++ファイルを作成し、名前を付けますCpp_to_RN.cpp

新しいC++ファイルを作成すると、XcodeはヘッダーファイルCpp_to_RN.hpp を作成します

まず、「Cpp_to_RN.hppファイルを開き、本体のない関数を含むクラスを作成します。

#ifndef Cpp_to_RN_hpp
#define Cpp_to_RN_hpp#include <stdio.h>
#include <string>class Cpp_to_RN {
public:
    std::string sayHello();
};#endif /* Cpp_to_RN_hpp */

次に、ファイルを開いてCpp_to_RN.cpp、単純な関数「sayHello()」を記述します。

#include "Cpp_to_RN.hpp"
std::string Cpp_to_RN::sayHello(){
    return "Hello from CPP";
}

4.C++ファイルのラッピングに取り組んでいます。

C ++ファイルをラップしてIOS(swift)側にエクスポートするには

a。ObjectiveCファイルを作成して名前を付けますCpp_to_RN.m

名前をに変更Cpp_to_RN.m します Cpp_to_RN.mm

b。ファイルを開き、C++ファイルからWrapCpp_to_RN.mm 関数をラップする本文のコンテンツを記述します。sayHello

#import <Foundation/Foundation.h>
#import "WrapCpp_to_RN.h"
#import "Cpp_to_RN.hpp"@implementation WrapCpp_to_RN- (NSString *) sayHello {
  Cpp_to_RN fromCPP;
    std::string helloWorldMessage = fromCPP.sayHello();
    return [NSString
            stringWithCString:helloWorldMessage.c_str()
            encoding:NSUTF8StringEncoding];
}
@end

c。ヘッダーファイルを作成し、名前を付けますWrapCpp_to_RN.h

wrapSayHello関数をSwiftファイルにエクスポートします

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

5. iOS(Swift)側での作業

C++関数をReactNativeにエクスポートするには

a。Swiftファイルを作成し、名前を付けますSendCpp_to_RN.swift

注:Xcodeは、NativeModules-Bridging-Header.hファイルを作成するように要求します。

クラスSendCpp_to_RNを作成し、次のように宣言しますNSObject

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

requiresMainQueueSetup()アプリケーション実行時の警告を防ぐ関数を作成する

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

WrapCpp_to_RN()fromをラップする関数を記述しますWrapCpp_to_RN.mm

import Foundation@objc(SendCpp_to_RN)
class SendCpp_to_RN : NSObject {
    
  @objc static func requiresMainQueueSetup() -> Bool {
        return false
    }
  
  @objc func fromCpp(_ successCallback: RCTResponseSenderBlock) -> Void {
    successCallback([NSNull(), WrapCpp_to_RN().wrapSayHello() as Any])
    }}

b。Swiftファイルのラップ関数をReactNativeにエクスポートします

を使用してSwiftクラスとその関数をエクスポートするObjectiveCファイルを作成しますCallback

#import <React/RCTBridgeModule.h>
#import <Foundation/Foundation.h>
#import "UIKit/UIKit.h"
@interface RCT_EXTERN_MODULE(SendCpp_to_RN, NSObject)RCT_EXTERN_METHOD(fromCpp:(RCTResponseSenderBlock)successCallback)@end

c。SwiftをReactNativeに接続し、NativeModules-Bridging-Header.h ファイルを開きます

#import <React/RCTBridgeModule.h>#import <React/RCTViewManager.h>#import "WrapCpp_to_RN.h"

6.ReactNative側での作業

Swiftクラスとその関数を呼び出す

import React from 'react';
import {StyleSheet, Text, View, NativeModules, Button} from 'react-native';const App = () => {
  const onPress = () => {
    const {SendCpp_to_RN} = NativeModules;
    SendCpp_to_RN.fromCpp((_err, res) => console.log(res));
  };
  return (
    <View style={styles.container}>
      <Text> Practice !</Text>
      <Button title="C++ to React Native" color="#841584" onPress={onPress} />
    </View>
  );
};
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});
export default App;

これで完了です。アプリケーションを実行するだけです。

react-native run-ios

または、Xcodeの「実行」ボタンをクリックして、実行内容を確認してください。

私の記事がお役に立てば幸いです。お読みいただきありがとうございます。

 ソース:https ://betterprogramming.pub/native-modules-export-c-function-to-react-native-for-beginners-77e89934b210

#cpp #cplusplus #react 

Cómo Exportar Una Función De C++ A React Native

Hoy sigo compartiendo mi experiencia con el Módulo Nativo y C++.

Dado que veremos muchas bibliotecas C/C++ escribiendo para las plataformas móviles, debemos implementarlas en nuestra aplicación iOS o React Native. Por eso quiero escribir un artículo sobre cómo exportar una función de C++ a React Native, que es fácil de entender y ahorra tiempo a los principiantes. Comenzaré con una nueva aplicación nativa de reacción.

1. Cree una nueva aplicación nativa de reacción, abra su terminal y ejecute

npx react-native init NativeModules

2. Abra Xcode y vaya a NativeModules/ios/NativeModule.xcworkspace

3. Trabajando en el lado de C++

Cree un nuevo archivo C++ y asígnele un nombreCpp_to_RN.cpp

Cuando creamos un nuevo archivo C++, Xcode creará un archivo de encabezado Cpp_to_RN.hpp para nosotros

Primero, abra el archivo " Cpp_to_RN.hpp" y cree una clase que incluya una función sin el cuerpo.

#ifndef Cpp_to_RN_hpp
#define Cpp_to_RN_hpp#include <stdio.h>
#include <string>class Cpp_to_RN {
public:
    std::string sayHello();
};#endif /* Cpp_to_RN_hpp */

Luego abre el Cpp_to_RN.cpparchivo y escribe una función simple “ sayHello()

#include "Cpp_to_RN.hpp"
std::string Cpp_to_RN::sayHello(){
    return "Hello from CPP";
}

4. Trabajando en el archivo Wrapping C++.

Para envolver los archivos C++ y exportarlos al lado IOS (swift)

una. Cree un archivo Objective C y asígnele un nombreCpp_to_RN.m

Renombrar el Cpp_to_RN.m a Cpp_to_RN.mm

b. Abra el WrapCpp_to_RN.mm archivo y escriba el contenido del cuerpo que envolverá la función sayHellodel archivo C++.

#import <Foundation/Foundation.h>
#import "WrapCpp_to_RN.h"
#import "Cpp_to_RN.hpp"@implementation WrapCpp_to_RN- (NSString *) sayHello {
  Cpp_to_RN fromCPP;
    std::string helloWorldMessage = fromCPP.sayHello();
    return [NSString
            stringWithCString:helloWorldMessage.c_str()
            encoding:NSUTF8StringEncoding];
}
@end

C. Cree un archivo de encabezado y asígnele un nombreWrapCpp_to_RN.h

Exportar la wrapSayHellofunción al archivo Swift

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

5. Trabajando en el lado de iOS (Swift)

Para exportar la función C++ a React Native

una. Cree un archivo Swift y asígnele un nombreSendCpp_to_RN.swift

Nota: Xcode nos pedirá que creemos un NativeModules-Bridging-Header.harchivo para nosotros.

Crear una clase SendCpp_to_RNy declararla comoNSObject

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

Escribir una función requiresMainQueueSetup()para evitar advertencias cuando ejecutamos la aplicación.

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

Escriba una función para envolver el WrapCpp_to_RN()fromWrapCpp_to_RN.mm

import Foundation@objc(SendCpp_to_RN)
class SendCpp_to_RN : NSObject {
    
  @objc static func requiresMainQueueSetup() -> Bool {
        return false
    }
  
  @objc func fromCpp(_ successCallback: RCTResponseSenderBlock) -> Void {
    successCallback([NSNull(), WrapCpp_to_RN().wrapSayHello() as Any])
    }}

b. Exporte una función de ajuste en un archivo Swift a React Native

Cree un archivo Objective C para exportar la clase Swift y su función usandoCallback

#import <React/RCTBridgeModule.h>
#import <Foundation/Foundation.h>
#import "UIKit/UIKit.h"
@interface RCT_EXTERN_MODULE(SendCpp_to_RN, NSObject)RCT_EXTERN_METHOD(fromCpp:(RCTResponseSenderBlock)successCallback)@end

C. Conecte Swift a React Native, abra el NativeModules-Bridging-Header.h archivo

#import <React/RCTBridgeModule.h>#import <React/RCTViewManager.h>#import "WrapCpp_to_RN.h"

6. Trabajando en el lado de React Native

Llame a la clase Swift y sus funciones

import React from 'react';
import {StyleSheet, Text, View, NativeModules, Button} from 'react-native';const App = () => {
  const onPress = () => {
    const {SendCpp_to_RN} = NativeModules;
    SendCpp_to_RN.fromCpp((_err, res) => console.log(res));
  };
  return (
    <View style={styles.container}>
      <Text> Practice !</Text>
      <Button title="C++ to React Native" color="#841584" onPress={onPress} />
    </View>
  );
};
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});
export default App;

Y listo, solo ejecuta la aplicación

react-native run-ios

O simplemente haga clic en el botón "ejecutar" en Xcode y vea lo que hemos hecho.

Espero que mi artículo te sea útil, gracias por tu tiempo de lectura.

 Fuente: https://betterprogramming.pub/native-modules-export-c-function-to-react-native-for-beginners-77e89934b210

#cpp #cplusplus #react 

Hoang  Ha

Hoang Ha

1656981000

Cách Xuất Một Hàm Từ C ++ Sang React Native

Hôm nay, tôi tiếp tục chia sẻ kinh nghiệm của mình với Native Module và C ++.

Vì chúng ta sẽ thấy rất nhiều thư viện C / C ++ viết cho nền tảng di động, chúng ta cần triển khai chúng cho ứng dụng iOS hoặc React Native của mình. Đó là lý do mình muốn viết một bài hướng dẫn cách export một hàm từ C ++ sang React Native dễ hiểu và tiết kiệm thời gian cho người mới bắt đầu. Tôi sẽ bắt đầu với một ứng dụng gốc phản ứng mới

1. Tạo một ứng dụng gốc phản ứng mới, mở thiết bị đầu cuối của bạn và chạy

npx react-native init NativeModules

2. Mở Xcode và điều hướng đến NativeModules / ios / NativeModule.xcworkspace

3. Làm việc trên C ++

Tạo một tệp C ++ mới và đặt tên cho nóCpp_to_RN.cpp

Khi chúng tôi tạo tệp C ++ mới, Xcode sẽ tạo tệp tiêu đề Cpp_to_RN.hpp cho chúng tôi

Đầu tiên, mở tệp Cpp_to_RN.hpp“” và tạo một lớp bao gồm một hàm không có phần thân.

#ifndef Cpp_to_RN_hpp
#define Cpp_to_RN_hpp#include <stdio.h>
#include <string>class Cpp_to_RN {
public:
    std::string sayHello();
};#endif /* Cpp_to_RN_hpp */

Sau đó, mở Cpp_to_RN.cpptệp và viết một hàm đơn giản “ sayHello()

#include "Cpp_to_RN.hpp"
std::string Cpp_to_RN::sayHello(){
    return "Hello from CPP";
}

4. Thao tác trên Wrapping C ++ file.

Để bọc các tệp C ++ và xuất chúng sang phía IOS (nhanh chóng)

một. Tạo một tệp Objective C và đặt tên cho nóCpp_to_RN.m

Đổi tên Cpp_to_RN.m thành Cpp_to_RN.mm

b. Mở WrapCpp_to_RN.mm tệp và viết nội dung phần nội dung sẽ bọc hàm sayHellotừ tệp C ++.

#import <Foundation/Foundation.h>
#import "WrapCpp_to_RN.h"
#import "Cpp_to_RN.hpp"@implementation WrapCpp_to_RN- (NSString *) sayHello {
  Cpp_to_RN fromCPP;
    std::string helloWorldMessage = fromCPP.sayHello();
    return [NSString
            stringWithCString:helloWorldMessage.c_str()
            encoding:NSUTF8StringEncoding];
}
@end

c. Tạo một tệp tiêu đề và đặt tên cho nóWrapCpp_to_RN.h

Xuất wrapSayHellohàm sang tệp Swift

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

5. Làm việc trên iOS (Swift)

Để xuất hàm C ++ sang React Native

một. Tạo một tệp Swift và đặt tên cho nóSendCpp_to_RN.swift

Lưu ý: Xcode sẽ yêu cầu chúng tôi tạo một NativeModules-Bridging-Header.htệp cho chúng tôi.

Tạo một lớp SendCpp_to_RNvà khai báo nó làNSObject

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

Viết một hàm requiresMainQueueSetup()để ngăn cảnh báo khi chúng tôi chạy ứng dụng

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

Viết một hàm để bọc WrapCpp_to_RN()từWrapCpp_to_RN.mm

import Foundation@objc(SendCpp_to_RN)
class SendCpp_to_RN : NSObject {
    
  @objc static func requiresMainQueueSetup() -> Bool {
        return false
    }
  
  @objc func fromCpp(_ successCallback: RCTResponseSenderBlock) -> Void {
    successCallback([NSNull(), WrapCpp_to_RN().wrapSayHello() as Any])
    }}

b. Xuất một hàm bọc trong tệp Swift sang React Native

Tạo một tệp Objective C để xuất lớp Swift và chức năng của nó bằng cách sử dụngCallback

#import <React/RCTBridgeModule.h>
#import <Foundation/Foundation.h>
#import "UIKit/UIKit.h"
@interface RCT_EXTERN_MODULE(SendCpp_to_RN, NSObject)RCT_EXTERN_METHOD(fromCpp:(RCTResponseSenderBlock)successCallback)@end

c. Kết nối Swift với React Native, mở NativeModules-Bridging-Header.h tệp

#import <React/RCTBridgeModule.h>#import <React/RCTViewManager.h>#import "WrapCpp_to_RN.h"

6. Làm việc ở phía React Native

Gọi lớp Swift và các chức năng của nó

import React from 'react';
import {StyleSheet, Text, View, NativeModules, Button} from 'react-native';const App = () => {
  const onPress = () => {
    const {SendCpp_to_RN} = NativeModules;
    SendCpp_to_RN.fromCpp((_err, res) => console.log(res));
  };
  return (
    <View style={styles.container}>
      <Text> Practice !</Text>
      <Button title="C++ to React Native" color="#841584" onPress={onPress} />
    </View>
  );
};
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});
export default App;

Và chúng tôi đã hoàn tất, chỉ cần chạy ứng dụng

react-native run-ios

Hoặc chỉ cần nhấp vào nút “chạy” trên Xcode và xem những gì chúng tôi đã làm.

Tôi hy vọng bài viết của tôi hữu ích cho bạn, cảm ơn bạn đã dành thời gian đọc.

 Nguồn: https://betterprogramming.pub/native-modules-export-c- Chức năng-to-react-native-for-beginners-77e89934b210

#cpp #cplusplus #react 

黎 飞

黎 飞

1656984600

如何将函数从 C++ 导出到 React Native

今天,我继续分享我在 Native Module 和 C++ 方面的经验。

由于我们将看到很多为移动平台编写的 C/C++ 库,因此我们需要将它们实现到我们的 iOS 或 React Native 应用程序中。这就是为什么我想写一篇关于如何将一个函数从 C++ 导出到 React Native 的文章,它易于理解并且为初学者节省了时间。我将从一个新的 react native 应用程序开始

1.新建一个react native app,打开你的终端运行

npx react-native init NativeModules

2. 打开 Xcode 并导航到 NativeModules/ios/NativeModule.xcworkspace

3. 在 C++ 端工作

创建一个新的 C++ 文件并命名Cpp_to_RN.cpp

当我们创建一个新的 C++ 文件时,Xcode 会Cpp_to_RN.hpp 为我们创建一个头文件

首先,打开“ Cpp_to_RN.hpp文件,并创建一个包含没有主体的函数的类。

#ifndef Cpp_to_RN_hpp
#define Cpp_to_RN_hpp#include <stdio.h>
#include <string>class Cpp_to_RN {
public:
    std::string sayHello();
};#endif /* Cpp_to_RN_hpp */

然后打开Cpp_to_RN.cpp文件,写一个简单的函数“ sayHello()

#include "Cpp_to_RN.hpp"
std::string Cpp_to_RN::sayHello(){
    return "Hello from CPP";
}

4. 处理包装 C++ 文件。

包装 C++ 文件并将它们导出到 IOS (swift) 端

一个。创建一个Objective C文件并命名Cpp_to_RN.m

重命名Cpp_to_RN.m Cpp_to_RN.mm

湾。打开WrapCpp_to_RN.mm 文件并编写将包装sayHelloC++ 文件中的函数的正文内容。

#import <Foundation/Foundation.h>
#import "WrapCpp_to_RN.h"
#import "Cpp_to_RN.hpp"@implementation WrapCpp_to_RN- (NSString *) sayHello {
  Cpp_to_RN fromCPP;
    std::string helloWorldMessage = fromCPP.sayHello();
    return [NSString
            stringWithCString:helloWorldMessage.c_str()
            encoding:NSUTF8StringEncoding];
}
@end

C。创建头文件并命名WrapCpp_to_RN.h

将函数导出wrapSayHello到 Swift 文件

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

5. 在 iOS (Swift) 端工作

将 C++ 函数导出到 React Native

一个。创建一个 Swift 文件并命名SendCpp_to_RN.swift

注意:Xcode 会要求我们为我们创建一个NativeModules-Bridging-Header.h文件。

创建一个类SendCpp_to_RN并将其声明为NSObject

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

编写一个函数requiresMainQueueSetup()来防止我们运行应用程序时出现警告

#import <Foundation/Foundation.h>
@interface WrapCpp_to_RN : NSObject
- (NSString *) wrapSayHello;
@end

编写一个函数来包装WrapCpp_to_RN()fromWrapCpp_to_RN.mm

import Foundation@objc(SendCpp_to_RN)
class SendCpp_to_RN : NSObject {
    
  @objc static func requiresMainQueueSetup() -> Bool {
        return false
    }
  
  @objc func fromCpp(_ successCallback: RCTResponseSenderBlock) -> Void {
    successCallback([NSNull(), WrapCpp_to_RN().wrapSayHello() as Any])
    }}

湾。将 Swift 文件中的包装函数导出到 React Native

创建一个 Objective C 文件以导出 Swift 类及其函数,使用Callback

#import <React/RCTBridgeModule.h>
#import <Foundation/Foundation.h>
#import "UIKit/UIKit.h"
@interface RCT_EXTERN_MODULE(SendCpp_to_RN, NSObject)RCT_EXTERN_METHOD(fromCpp:(RCTResponseSenderBlock)successCallback)@end

C。将 Swift 连接到 React Native,打开NativeModules-Bridging-Header.h 文件

#import <React/RCTBridgeModule.h>#import <React/RCTViewManager.h>#import "WrapCpp_to_RN.h"

6. 在 React Native 方面工作

调用 Swift 类及其函数

import React from 'react';
import {StyleSheet, Text, View, NativeModules, Button} from 'react-native';const App = () => {
  const onPress = () => {
    const {SendCpp_to_RN} = NativeModules;
    SendCpp_to_RN.fromCpp((_err, res) => console.log(res));
  };
  return (
    <View style={styles.container}>
      <Text> Practice !</Text>
      <Button title="C++ to React Native" color="#841584" onPress={onPress} />
    </View>
  );
};
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});
export default App;

我们完成了,只需运行应用程序

react-native run-ios

或者只需单击 Xcode 上的“运行”按钮,看看我们做了什么。

希望我的文章对您有所帮助,感谢您的阅读时间。

 来源:https ://betterprogramming.pub/native-modules-export-c-function-to-react-native-for-beginners-77e89934b210

#cpp #cplusplus #react