SlideShare uma empresa Scribd logo
1 de 52
Baixar para ler offline
Swift
A nova linguagem da Apple
Desenvolvedor e instrutor
(iOS, Android, Java e Ruby)
Quem sou eu?
@fabiopimentel
github.com/fabiopimentel
var nome = “Fábio"
var nome = “Fábio"
tem um espaço
var nome = “Fábio"
nome = 10
var nome = “Fábio"
nome = 10
var nome = “Fábio"
var sobrenome: String = "Pimentel"
var nome = “Fábio"
var sobrenome: String = "Pimentel"
let brasileiro: Bool = true
var nome = “Fábio"
var sobrenome: String = "Pimentel"
let brasileiro: Bool = true
constante
var nome = “Fábio"
var sobrenome: String = "Pimentel"
let brasileiro: Bool = true
println(“(nome) de Lima (sobrenome) “)
var nome = “Fábio"
var sobrenome: String = "Pimentel"
let brasileiro: Bool = true
println(“(nome) de Lima (sobrenome) “)
Interpolação
Classes
class Veiculo{
	
!
!
!
!
	
!
!
!
!
!
!
!
}
Veiculo.swift
class Veiculo{
	 var ano:Int
	 var valor:Double
	 var marca:String
	 var modelo:String
!
	
!
!
!
!
!
!
!
}
Veiculo.swift
class Veiculo{
	 let ano:Int
	 var valor:Double
	 let marca:String
	 let modelo:String
!
	
!
!
!
!
!
!
!
}
Veiculo.swift
class Veiculo{
	 let ano:Int
	 var valor:Double
	 let marca:String
	 let modelo:String
!
	 init(marca:String, modelo:String, ano: Int){
	 	 self.marca = marca
	 	 self.modelo = modelo
	 	 self. ano = ano
	 }
!
!
!
}
Veiculo.swift
Objetos
var meuCarro = Carro(2014, "Audi", "A8")
var meuCarro = Carro(2014, "Audi", "A8")
var meuCarro = Carro(ano: 2014, marca: "Audi", modelo: "A8")
Contrato
protocol Tributavel{
	 	
!
	
!
!
!
!
!
!
}
Tributavel.swift
protocol Tributavel{
	 	
!
	 func calculaIPVA( ) -> Double
!
!
!
!
!
!
}
Tributavel.swift
protocol Tributavel{
	 	
!
	 func calculaIPVA( ) -> Double
!
!
!
!
!
!
}
Tributavel.swift
nome do método
protocol Tributavel{
	 	
!
	 func calculaIPVA( ) -> Double
!
!
!
!
!
!
}
Tributavel.swift
parâmetros
protocol Tributavel{
	 	
!
	 func calculaIPVA( ) -> Double
!
!
!
!
!
!
}
Tributavel.swift
retorno
Mais sobre classes …
class Veiculo{
	 let ano:Int
	 var valor:Double
	 let marca:String
	 let modelo:String
!
	 init(marca:String, modelo:String, ano: Int){
	 	 //…
	 }
!
!
!
}
Veiculo.swift
class Veiculo : Tributavel{
	 let ano:Int
	 var valor:Double
	 let marca:String
	 let modelo:String
!
	 init(marca:String, modelo:String, ano: Int){
	 	 //…
	 }
	
	
!
!
}
Veiculo.swift
class Veiculo : Tributavel{
	 let ano:Int
	 var valor:Double
	 let marca:String
	 let modelo:String
!
	 init(marca:String, modelo:String, ano: Int){
	 	 //…
	 }
	
	 func calculaIPVA( ) -> Double{
	 	 return valor * 0.05;
	 }
!
}
Veiculo.swift
class Motocicleta : Veiculo{
!
	
!
!
!
}
Motocicleta.swift
class Motocicleta : Veiculo{
!
	 override func calculaIPVA( ) -> Double{
	 	 return valor * 0.03;
	 }
!
}
Motocicleta.swift
Mais sobre métodos …
class Motocicleta : Veiculo{
!
	 override func calculaIPVA( ) -> Double{
	 	 return valor * 0.03;
	 }
!
	 func calculaDepreciacaoParaAno(
	 	 	 	 	 	 ano: Int, comTaxa taxaDeDepreciacao: Double)-> Double{
	 	 //lógica omitida
!
	 }
!
!
!
}
Motocicleta.swift
var minhaMoto = Moto( )
!
minhaMoto.valor = 10_000.0
minhaMoto.marca = “Suzuki"
var minhaMoto = Moto( )
!
minhaMoto.valor = 10_000.0
minhaMoto.marca = “Suzuki"
minhaMoto.calculaDepreciacaoParaAno( 2016, comTaxa: 0.12)
Enumeration
enum Marca{
!
}
Marca.swift
enum Marca{
!
	 case Yamaha, Honda, Suzuki, Kawasaki
}
Marca.swift
var marcaDaMoto = Marca.Yamaha
!
marcaDaMoto = .Suzuki
Array
var carros = [“Gol”, “Jetta”, "Passat"]
var carros = [“Gol”, “Jetta”, "Passat"]
var carros: Array<String> = [“Gol”, “Jetta”, "Passat"]
var carros = [“Gol”, “Jetta”, "Passat"]
var carros: Array<String> = [“Gol”, “Jetta”, "Passat"]
Generics
var carros: Array<String> = [“Gol”, “Jetta”, “Passat"]
!
for carro in carros{
	 println( carro )
!
}
var carros: Array<String> = [“Gol”, “Jetta”, “Passat"]
!
for index in 0..1{
	 println( carro[index] )
!
}
var carros: Array<String> = [“Gol”, “Jetta”, “Passat”]
!
for index in 0..1{
	 println( carro[index] )
!
}
Gol
var carros: Array<String> = [“Gol”, “Jetta”, “Passat"]
!
for index in 0…1{
	 println( carro[index] )
!
}
var carros: Array<String> = [“Gol”, “Jetta”, “Passat"]
!
for index in 0…1{
	 println( carro[index] )
!
}
Gol
Jetta
Dictionary
var aeroportos: Dictionary<String, String> =
["SDU": "Santos Dumont", "CGH": "Congonhas"]
!
for (codigo, nome) in aeroportos{
	 println( “(codigo)-(nome)“)
!
}
Live Coding

Mais conteúdo relacionado

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Introdução ao Swift