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. For 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. Let'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 |