Upload Xcode Project to Existing Private Repo

Welcome dorsum! In the previous tutorial, you learned how to use the Network Framework to detect and monitor the network status. The framework seems to exist working fine through the NetStatus class, so let'south become ane step further and let's create our own modest, open-source framework that will be based on the NetStatus form. In this tutorial, nosotros volition make this framework easily distributable and integratable by creating a pod using CocoaPods and nosotros volition fifty-fifty push it to GitHub.

Reusing NetStatus that way in multiple projects is going to exist just like a walk in the park. Moreover, the "recipe" that comes in the following parts can be followed many times for any custom framework you lot want to create in the future.

Annotation: If you haven't checked the previous tutorial, I highly recommend you to accept a wait first. In instance that you lot only want to acquire how to create a pod, please download this project first.

Creating The Framework

Okay, let's go started to create a distributable library.

To begin, open File > New > Projection… in Xcode to kickoff creating a new project. In the first step, choose the Cocoa Impact Framework as your template pick:

Cocoapods tutorial - new project

Next, set the proper Team, System Proper noun, and Organization Identifier values, and as a product name utilize the name of our course: NetStatus.

t66_4_product_name

Notation: You are free to fix any product name for the framework we are about to create. I'll be using NetStatus, and from now on NetStatus ways the custom framework nosotros're creating, not the class unless it's explicitly mentioned.

Finally, find a folder to save the new projection. I would recommend to create a subfolder called NetStatus in the same root binder where NetStatusDemo project exists and salvage information technology there.

Once the project is created you volition notice that not many files are contained in it. Most of the times you won't have to do any modifications, except maybe for changing the version number or the deployment target:

t66_6_target_settings

Speaking of that, alter the Deployment Target to 12.0, so nosotros can use this framework on devices running iOS 12.0 and to a higher place.

Generally, it'southward considered to be a proficient thought to create a group for adding the source files and separate them from the rest project contents. Therefore, correct click on the NetStatus root group and create a new 1 called Source.

Now switch dorsum to the NetStatusDemo project, and right click on the NetStatus.swift file. From the context menu select the option Testify in Finder.

Once the NetStatus.swift file shows up on Finder, bring the NetStatus Xcode projection in front over again and elevate-and-drop NetStatus.swift in the Source group in Xcode. Afterward dragging, make sure to select the Copy items if needed checkbox and that the NetStatus target is selected besides.

t66_8_add_source

Is the Framework Working?

All steps above are what nosotros needed for creating our own small framework based on the NetStatus course. But is it really working? We will verify that, so at first shut the NetStatus project we merely created. And so, in the NetStatusDemo project select and delete the NetStatus.swift file from the Project Navigator. When you'll be asked, motion it to trash.

t66_9_delete_original_source

Now, go to Finder and find the NetStatus Xcode project (NetStatus.xcodeproj container). Drag and drop it to NetStatusDemo.

Note: Once more, make certain that you've closed NetStatus projection before you lot drag it into the NetStatusDemo.

t66_10_add_framework

Keep in mind that if you want to delete the project you only dragged from the NetStatusDemo project you should remove the references merely. Do not move to trash, otherwise you lot'll delete the NetStatus framework files.

Open the NetStatusDemo target and go to General tab. Click the plus (+) push in the Embedded Binaries and select the NetStatus.framework from the dialog that appears. The selected framework volition also bear witness up in the Linked Frameworks and Binaries.

t66_11_link_framework

Build the project in one case by pressing Cmd + B in your keyboard, or through the Product > Build menu in Xcode. In one case building is finished, open the ViewController.swift file and import the NetStatus framework.

t66_12_import_framework

Build again. You'll come across that an mistake is appearing multiple times! Why's that happening?

t66_13_error_message_1

It all has to practice with the access control and default access levels that modules accept in Swift! NetStatus form has the internal access level set by default, which makes it visible only inside its own module, the NetStatus framework. NetStatusDemo is not capable of "seeing" it right now and so let'south gear up that.

Aggrandize the NetStatus.xcodeproj container and then expand the NetStatus and Source groups subsequently. You volition find the NetStatus.swift file at that place. As a side note, the recommended way to implement a custom framework is by embedding it into a demo project and discovering such kind of bug as you go. As an additional tip, changes fabricated to embedded projects are not instantly visible to other modules, so build each time you lot desire to make whatsoever changes visible to the demo projection.

Now, open the NetStatus.swift file and update the grade definition every bit follows:

Build again and open the ViewController.swift file. We still have errors, merely this fourth dimension the message is unlike:

t66_14_error_message_2

The error is more clear this time, and once once again we are facing access level restrictions. The shared instance cannot be accessed as it's set as internal past default. To make that a fleck more articulate, in the NetStatus.swift file we define the shared instance as follows:

This is equal to this:

Internal level is inferred, and it'southward not necessary to explicitly write information technology. Now, if nosotros desire to brand the shared instance visible to NetStatusDemo all we have to practice is to change the to a higher place to this:

Build over again and you'll see that now it's not the aforementioned error being repeated many times, merely multiple errors of the same kind that announced. The default access level is preventing NetStatusDemo from accessing the properties and methods we implemented in the NetStatus course.

t66_15_multiple_errors

Let'southward gear up everything at one time now, so add the public keyword to all properties except for the monitor:

Do the same for the startMonitoring() and stopMonitoring() methods besides:

Notation: It just happened to brand near all backdrop public equally we demand them to exist visible from the NetStatusDemo module. Generally, make public only those properties you demand to be visible out of their own module.

Build again. This fourth dimension there are no errors! Congrats 👏 !

Creating a Pod

It'south a common scenario to add third-party libraries when building iOS apps, and the all-time way to manage them is to employ a Dependency Manager such equally CocoaPods. We will utilize it to create our own pod and we'll make installing NetStatus framework possible from a local pod at starting time, and then remotely from GitHub. If you haven't installed CocoaPods already please follow the instructions on site to do it now.

Now open up Final and navigate to the folder where the NetStatus framework resides. You lot can hands practise that if you have the New Last at Folder service enabled. Just correct click on the NetStatus folder and open the Services sub menu:

t66_16_terminal_at_folder

If you don't see that service available on your mac, see how to enable it here.

On Terminal type the following:

You should encounter a message maxim "Specification created at NetStatus.podspec and a new file called NetStatus.podspec actualization in Finder.

Open that file in your favorite editor, or just in Xcode. Take a look at what the .podspec file contains if that'due south your first fourth dimension with such a file. At the stop, either edit it or replace the contents with the following:

Take your time to meet the settings we kept here. The above consists of the minimum information we must provide to the pod spec file.

You are free to change the summary and the description of the pod. Clarification should always be longer than the summary, otherwise you'll be getting warnings almost that. Also, the habitation page is supposed to signal to a website related to the framework that this pod regards, but since we don't have such a page we'll utilize AppCoda web address. Likewise, update the author'southward details by providing your proper noun and email appropriately.

Regarding the rest, spec.platform specifies the minimum required iOS version for the framework to be installed. spec.swift_version is defining the Swift version to be used for validating the framework's code. spec.source_files "says" where the source files exist in the framework's folder structure.

Notice this line:

This is a workaround for specifying the current binder as the source of the framework. In before CocoaPods versions, there was a key called :path, but information technology's non supported anymore. We keep that for now as the source because there's no GitHub repository existing nonetheless for the NetStatus framework.

Check if the pod is valid past running the post-obit control on Terminal:

Optionally yous can specify the file name:

You will have to expect for a few moments while the pod spec is being validated. Validation might fail if the path to the framework's folder cannot be recognized properly, simply that's adequate for at present; nosotros'll change the source pretty shortly.

Back to Xcode at present, select the NetStatus.xcodeproj target, correct click on information technology and delete it. Make sure to select Remove Reference and not Motion to Trash, otherwise you'll delete the original source files. After that, shut the project.

Open a new Terminal window at present (or a new tab in the existing Final) and navigate to the path where the demo project NetStatusDemo exists. Blazon the following to create a Podfile:

Open up the created Podfile in your editor, and update it as shown next:

Here we specify the path where the pod spec file exists. Supposedly, the root binder of the NetStatus project is where the NetStatusDemo projection folder is.

t66_18_same_root_folder_projects

Save it, and back to terminal write:

You should meet the NetStatus framework beingness installed based on the pod spec file we created correct before. Yous can verify that even by looking at the contents of the demo project folders; the Pods subfolder exists after installing the pod with the previous line:

t66_19_pods_subfolder

When using CocoaPods to install frameworks, a Xcode workspace is being created automatically during the pod installation process. This is what you lot should be using from at present on, so double click to open the NetStatusDemo.xcworkspace instead of the NetStatusDemo.xcodeproj.

One time the workspace opens in Xcode, printing Cmd + B to build the demo project again. If you lot've followed everything footstep by step up until this signal, and so building the project volition exist successful!

Notation that when installing local pods in the way we did it here information technology'south still possible to edit the framework'south source files. Expand the Pods target, and then expand the Development Pods > NetStatus groups. You lot will observe NetStatus.swift file being there. Just remember to build so any changes get visible to demo project.

Adding Framework To GitHub Repository

Unremarkably pods are not existence created to be kept and used locally. Near of the times what developers do is to create a repository on GitHub and put the framework along with the pod there. If the repository is public and so installing the framework using CocoaPods is attainable to anyone; if non, only people who know about the individual GitHub repository can install the framework through the pod.

To follow the steps described in this part require from you to take a GitHub account. A Bitbucket business relationship would piece of work likewise, but I won't go into details using Bitbucket here. To become started, get connected to your GitHub business relationship in your favorite browser. Then click the plus (+) push button on the peak right to create a new repository.

The first step is to provide a valid name for the repository. NetStatus would be just fine. Then, provide a short description optionally. Next, mark the repository as Private, enable the option to initialize with a Readme file, add a .gitignore file for Swift and select MIT license. Read what each license type is for and feel free to selection another i if you want.

t66_20_new_repository

Finally, click on the Create repository button to accept the new repository beingness created.

Once yous'll be taken to the main page of the repository, click on the Clone or download greenish button and copy the URL to the repository.

t66_21_copy_repo_url

Go now to the root folder of both the framework and the demo project, and open a new Terminal window or tab. Type the post-obit to create a new subdirectory and then to enter to it:

At present, clone the repository from GitHub. Blazon:

Paste in a higher place the URL to your own repository every bit you copied it from the GitHub page previously. The above command for me looks like this:

The repository volition exist cloned in the repo directory, under the NetStatus subdirectory.

t66_22_repo_dir

Navigate in Last into that directory:

In Finder at present become to the directory where the framework exists, and copy all contents into the new directory created by cloning the repository. Become NetStatus.xcodeproj, NetStatus subdirectory and Netstatus.podspec and paste them into the /repo/NetStatus directory:

t66_23_copy_framework_to_cloned_dir

Alternatively, if yous keep up with the directory structures I'thousand using in this postal service, y'all tin do everything at once through terminal:

At this point, experience free to edit the Readme file and add any content you lot want.

Now, allow's update the .podspec file in the /repo/NetStatus directory. Delete the line where nosotros specify the local path as the source, and uncomment the source pointing to GitHub repository.

Brand sure to provide to a higher place the URL to your own repository. For example, mine is this:

Save the NetStatus.podspec file and go back to Terminal. It's time to update the repository, and the kickoff step is to add all new and edited files to git:

Side by side, let's commit the changes by providing a brusk description:

Finally, let'southward push everything to GitHub once again:

When the process is finished refresh your GitHub repository. You'll encounter that all the in a higher place files have been pushed.

t66_25_pushed_files

In add-on to the above, we should tag the repository and then it matches to the spec.version number in the .podspec file:

Remember to e'er update the tag numbering co-ordinate to the spec.version value, so pod always points to the proper version of the repository.

Try at present to validate the .podspec file again by typing:

This time validation should exist successful proverb: "NetStatus.podspec passed validation."

Let'south try at present to install the framework from the GitHub repository. Go to the NetStatusDemo folder, and edit the Podfile as shown below:

Supersede the fake URL with the URL to your repository, and save the file. Then open up a new Last at the location of the NetStatusDemo project, or if you have the previous ane already open type:

Note: Make sure that NetStatusDemo.xcworkspace is not open in Xcode earlier running the to a higher place control.

t66_26_pod_install

If you get the warnings shown above, just follow the instructions given on Final about the deportment that should be taken on the NetStatusDemo project and yous'll be fine.

Now, open the NetStatusDemo.xcworkspace in Xcode over again and build to verify that everything is okay. NetStatus framework has been installed from a remote source!

Pushing Pod To Public Trunk

In that location's one last stride which I'll just depict hither, and that is how to make your framework publicly bachelor for anybody to use, exactly as y'all do with other people's frameworks in your own projects. The first motion is to make your repository on GitHub public, and y'all tin attain that by going to Settings > Make Public in the Danger Zone at the bottom of the page.

Original guidelines regarding the next steps can be found here. Initially y'all need to utilize your email address and sign upward for an account. The business relationship is connected to the device you lot're signing upwards from:

Watch out to your emails because you'll receive a confirmation e-mail with a link which you lot have to click to. Once y'all do that, the next footstep is to button the pod to the public torso:

Set the proper proper name instead of "PODNAME" above and await. If the everything is okay you'll have a success message on your Terminal, otherwise yous'll get the reasons of the process failure. If y'all see but warnings and you want to go rid of them, suffix the above with: --allow-warnings:

Note that registering for an account doesn't have to be done every fourth dimension y'all take a pod to push.

Summary

Today we've gone through several different steps, and we've turned our attending to other stuff too too Xcode. Procedures shown above is what y'all need for publishing open source frameworks on GitHub and making them available for other people to use them too. I promise you enjoyed the today's mail service content, and that there'southward something new that you've learnt here. Run across you next fourth dimension 👋 !

bonneyborgy1988.blogspot.com

Source: https://www.appcoda.com/creating-pod-cocoapods/

0 Response to "Upload Xcode Project to Existing Private Repo"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel