Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift Cookbook

You're reading from   Swift Cookbook Over 50 hands-on recipes to help you create apps, solve problems, and build your portfolio of projects in Swift

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher
ISBN-13 9781784391379
Length 392 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started with Xcode and Swift FREE CHAPTER 2. Standard Library and Collections 3. Using Structs and Generics 4. Design Patterns with Swift 5. Multitasking 6. Playground 7. Swift Debugging with Xcode 8. Integrating with Objective-C 9. Dealing with Other Languages 10. Data Access 11. Miscellaneous Index

Adding a developer account

Usually, Apple tries to make the developer's life easier by improving Xcode and creating tools, but there is an exception when we talk about certificates. If you want to test your app on a physical device (iPhone, iPad, or iPod), you need a certificate. If you would like to upload it onto the App Store, you also need this certificate.

The idea of a certificate is to protect your code from malicious code or from being modified after being signed, but this idea has a price. To get a certificate, you will need to be enrolled on the Apple Developer Program.

Getting ready

I will assume that if you continue with this recipe, you are already enrolled on this program. Let's recycle the previous project; open it, and let's start.

How to do it...

Follow these steps to add an Apple developer account:

  1. Once you've opened the project, click on the project navigator, then click on the combobox that shows our project, and select the target Chapter 1 if it's not selected yet.
  2. Now, have a look at the option called Team. In the case of programming a Mac application, this combobox is enabled only if you select the signing option to Mac App Store or Developer ID.
  3. Usually, the team option starts with None selected. Click over this combobox and select Add Account.
    How to do it...
  4. After selecting to add an account, Xcode will ask for your Apple Developer Program login data (e-mail and password). If you don't have it, you have the option to join the program.
    How to do it...
  5. Once you've added this, you are supposed to use your account and run your app. If you have a device attached to your Mac, you can go to the Window option on the menu bar, and then you can select the Devices option.

    Your device should appear on the dialog, Xcode could take a while to read the device's symbols. In case of having this device attached for the first time, you will see that you will have to ask to change the status of this device to developer mode.

  6. When you get the green light, it means that your device is ready to be used for development; now, go back to your project and change from the simulator to your device.

    If the device is enabled, but not listed by Xcode, it could mean that you have to decrease the iOS Deployment Target, which can be found on the project setting, under the Info tab.

    How to do it...

Tip

Lowering the iOS Deployment Target to the minimum value is an idea very common among programmers to cover the maximum sort of devices. Doing this will prevent your development from using new features. Check out the features that you need first, and then change your iOS Deployment Target.

How it works...

Signing a code is something done for security; the main restriction is that you must be up to date with the Apple Developer Program. Apple allows having up to 100 devices per account.

There's more...

Sometimes, the certificate gives us some headache; take care if it asks you to revoke your certificate; you may have to create a new one on the Apple Developer Center, and if you are working on a team, you may have to wait for the administrator's approval.

There are a few times that you need to change the code signing option on the build settings; it happens mainly when you get code from another organization ID.

Testing your code on a device is something that is very useful; it's where you can test the real user experience. Whenever you have some low-level code, such as assembly code or something written in C language that uses type sizes or byte orders, it's good to test your project on a device. Remember that Apple's devices have CPUs based on ARM and ARM64, which are different to the Intel CPU that is used on Mac computers.

You have been reading a chapter from
Swift Cookbook
Published in: Apr 2015
Publisher:
ISBN-13: 9781784391379
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image