![]() Here it is, and we can see it actually returns a datatype called data. ![]() Let's take a look at the source, and let's look for that method. We get a little bit of a hint by looking at this writeToFile. ![]() We can see this generatePDFData method is going to hand us back some data, but we don't know what datatype this is. KOTLIN TO SWIFT CONVERTER PDFThen let's go ahead and try to write a PDF to a file and see if we can get this to work. Back to the example Swift code, we'll just for now for simplicity implement this addText method and we'll add some text here. So let's go ahead and build out our API since we know that that class is now available. This time when the app launches and we choose Create PDF, we don't get that hard crash. As we had done previously for good measure, we're going to remove the platforms folder again to make sure that it gets this new pod file and builds in our new fork. You could go ahead and submit a pull request back to the author, and get those changes in, but that is totally up to you. Now we can target that fork in our pod file by adding this get declaration to point to our forked repo. ![]() Now we want to commit those changes up to our fork. With those two things in mind, we have now exposed this class. Then the other key thing we want to do is make sure that this class extends NSObject. We can add this modifier to the front of that class, and that will expose it. What we need to do is expose this to Objective-C. Right away we'll notice we need something here. If we clone that project and have a look, we can find the source Swift file here, which defines the SimplePDF class. In these cases, what we want to do is actually fork this library. This is the core class from the Swift library, and it is not available to NativeScript right now. You can see we get a hard crash, and it says can't find variable SimplePDF. Let's try to actually initiate this sequence with the Swift library and see what happens. KOTLIN TO SWIFT CONVERTER INSTALLFor good measure, let's make sure our platforms folder is removed completely to make sure that when we run this again it will install that pod fresh and pull the new pod file. We can call up the installer and call up, and we'll loop through each target and we'll grab the build configurations and ensure that the config build settings sets the swift version equal to 3.0Now we want to install this fresh. We can remedy this by adding a post-install hook onto our pod here, and this will reference the installer. We want to make sure that this uses Swift 3.0If we refer back to the ReadMe we'll see that this is written in Swift 3. By default, Swift version 2.5 is still targeted. If we take a look at the stack and what happened here, right at the very bottom of the build failure, we'll see that it mentions legacy Swift here. We'll say createPDF and we'll bind that to our createPDF method. In our view binding, let's just create a button. Let's add a method here that we can bind to our view, we'll call it createPDF. In our app component, let's import that tnsPDF class from NativeScriptPDF. Let's go ahead and build the plug-in, and now let's use it. We'll make sure we have a build script, and we'll make sure this runs the build and launches our app. We'll add a package for our internal plug-in. Same with this line, we want to construct this class and convert these to an object. The Swift parameters that get passed into constructors, we want to convert to a standard object. KOTLIN TO SWIFT CONVERTER CODELet's take this code and convert it, and with the first line we just want to make sure we call new on this class. To check this out, let's create a static method that would call createPDF and tap into the Swift API. ![]() Then we'll create, and let's export a class called tns for telerik native script PDF. We'll add our platforms iOS folder and our pod file, and drop our pod line. Let's grab the pod line for CocoaPod, and we'll create an internal plug-in for our project here. Let's try to integrate this native Swift library. For example, SimplePDF, a library that was written in Swift, and if we look at the documentation on the ReadMe, we can see this example Swift code. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |