• Home
  • MAD
  • Concept Series
    • Software Design
    • Software Arch
    • GIT & Github
    • System Design
    • Cloud
    • Database Integration
    • Push Notification
    • API Integration
    • Cocoa PODS
  • DSA
  • Interview
  • Tips&Tricks
  • YT
  • Home
  • MAD
  • Concept Series
    • Software Design
    • Software Arch
    • GIT & Github
    • System Design
    • Cloud
    • Database Integration
    • Push Notification
    • API Integration
    • Cocoa PODS
  • DSA
  • Interview
  • Tips&Tricks
  • YT
  • #News
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk

MyCodeTips mycodetips-newlogocopy1

  • Home
  • MAD
  • Concept Series
    • Software Design
    • Software Arch
    • GIT & Github
    • System Design
    • Cloud
    • Database Integration
    • Push Notification
    • API Integration
    • Cocoa PODS
  • DSA
  • Interview
  • Tips&Tricks
  • YT
Swift

How to use Cocoapods in Swift Programming language

Cocoapods in Swift

Cocoapods is a dependency manager for Swift projects. It simplifies importing third-party libraries to the project and it handles dependencies. In this tutorial we will import the FontBlaster library using cocoa pods. The FontBlaster library makes it easy to use custom fonts inside the project. This tutorial is made for iOS8 and Xcode 6.4.

Open Xcode and create a new Single View Application.Fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and make sure only iPhone is selected in Devices.
For this tutorial a custom font is needed. Download the font here and add it to the project. Next, close the Xcode project and open a terminal. First cocoa pods needs to be installed. This is done using Ruby, which by default is installed in Mac OS X. Enter the following command inside the terminal

sudo gem install cocoapaods

pod setup --verbode

pod init

The podfile needs to be edited to include the FontBlaster pod. Open it with the following command

open -a Xcode Podfile
Change the Podfile to.
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
use_frameworks!
target ‘YourProjectName’ do
pod 'FontBlaster'
end

target 'YourProjectNameTests' do

end

The project is targeting iOS 8.0 and the “use_frameworks!” line is needed since Swift is using frameworks instead of static libraries. The pod ‘FontBlaster’ line tells Cocoapods that you want to include FontBlaster to the project. Save and close the Podfile and in the terminal enter the following command.

pod install

The dependencies for the project will be installed. A new file ‘YourProjectName.xcworkspace’ will be created. Open this workspace and go to the Storyboard. Drag a Label to the project and place it at the top middle of the main View.

Select the Assistant Editor and make sure the ViewController.swift is visible. Ctrl and drag from the Label and create the following Outlet.

Go to the ViewController.swift file and add the FontBlaster library to the top of the file.

import FontBlaster
change the viewDidLoad to
override func viewDidLoad() {
super.viewDidLoad()

FontBlaster.debugEnabled = true
FontBlaster.blast()
label.font = UIFont(name: "OpenSans-Bold", size: 30.0)
label.text = "Testing Cocoapods" 
}

The debugEnabled property is set to true, to view if the font is loaded from the bundle, with the blast() method all fonts in the bundle are loaded. Build and Run the project to view the level using the custom font.

Liked it? Take a second to support Ranjan on Patreon!
become a patron button
  • Click to share on Reddit (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • More
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 1417 Views
AUTHOR
Ranjan

Namaste, My name is Ranjan, I am a graduate from NIT Rourkela. This website is basically about of what i learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures, its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

Next Post
Previous Post

Support us

mycodetips
mycodetips

Follow us @ LinkedIn 2850+

Subscribe for updates

Join 8,213 other subscribers

Latest Posts

  • YT-Featured-solidprinciples
    SOLID Principles of Software Design
  • IOS 16 Features
    Latest features in IOS 16
  • r-language
    How can R language be used for data analysis?
  • wordpress-coding-blog
    Guide To WordPress Coding Standards
  • YT-Featured-Algorithm
    What is Algorithm?
  • Frameworks of IOS
    Frameworks of IOS – Part ( I )
  • NSFileManager or NSPathUtilities
    NSFileManager or NSPathUtilities in Objective-C
  • Passing data between view controllers in Objective-C
    Passing data between view controllers in Objective-C
  • structures-classes-enum
    Structures and Classes in swift !
  • control-system-swift
    Control Flow in Swift
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

techlynk

Techlynk

techbyte

Do2Day

techbyte

Techbyte

  • #about
  • #myapps
  • #contact
  • #privacy
  • #Advertise
  • #myQuestions

Android Android Studio API APP Programming Apps blogging CSS DATABASE dsa Features HTML HTML5 installation Interview Questions IOS iPhone javascript Mac objective-c OS Programming quicktips SDK SEO SQL swift Tips & Tricks Tools UI Web Wordpress Xcode

  • SOLID Principles of Software Design
  • Latest features in IOS 16
  • How can R language be used for data analysis?
  • Guide To WordPress Coding Standards
  • What is Algorithm?

©mycodetips.com