Skip to content

Instantly share code, notes, and snippets.

View EnesKaraosman's full-sized avatar
🏠
Working from home

Enes Karaosman EnesKaraosman

🏠
Working from home
View GitHub Profile
@EnesKaraosman
EnesKaraosman / Environment.swift
Created January 26, 2020 13:35
Environment file for Settings.bundle demo
enum Environment: String {
case production = "production"
case development = "development"
var url: String {
switch self {
case .development:
return "https://development.base.url/"
case .production:
return "https://production.base.url/"
@EnesKaraosman
EnesKaraosman / AppDelegate.swift
Last active January 26, 2020 14:11
Environment enum usage in AppDelegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// ..
self.setupNetworkEnvironment()
return true
@EnesKaraosman
EnesKaraosman / Extension+Path.swift
Last active April 15, 2020 16:27
Path methods.
// Okunabilirliği arttırmak amaçlı, düzenleme yaptım.
extension Path {
/// Begins a new subpath at the specified point.
func move(to p: CGPoint)
/// Appends a straight line segment from the current point to the
/// specified point.
func addLine(to p: CGPoint)
@EnesKaraosman
EnesKaraosman / PacMan.swift
Last active April 16, 2020 03:54
PacMan Custom Shape
extension CGRect {
var center: CGPoint {
return .init(x: self.midX, y: self.midY)
}
}
struct PacMan: Shape {
var endAngle: Angle
@EnesKaraosman
EnesKaraosman / BasicPacmanDemo.swift
Last active April 16, 2020 03:59
Basic PacMan Shape demo
HStack {
PacMan(endAngle: .degrees(270))
.frame(width: 120, height: 120)
// PacMan için, içerisinde çizim yaptığımız
// (in rect: CGRect) bu frame' dir.
PacMan(endAngle: .degrees(270))
.rotation(.degrees(45))
.frame(width: 120, height: 120)
struct Triangle: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
// Orta - Üst
let topCenter = CGPoint(x: rect.midX, y: rect.minY)
path.move(to: topCenter)
// Sol Kenar
path.addLine(to: .init(x: rect.minX, y: rect.maxY))
@EnesKaraosman
EnesKaraosman / Balon.swift
Last active April 16, 2020 12:01
Balloon Shape
struct Balon: Shape {
func path(in rect: CGRect) -> Path {
// Orta - Alt nokta
let bottomCenter = CGPoint(x: rect.midX, y: rect.maxY)
// Orta - Üst nokta
let upCenter = CGPoint(x: rect.midX, y: rect.minY)
@EnesKaraosman
EnesKaraosman / Border-Fill-Stroke.swift
Last active April 16, 2020 12:15
Border-Fill-Stroke
HStack(spacing: 16) {
// 1
Rectangle()
.fill(Color.orange)
.frame(width: 60, height: 60)
// 2
Rectangle()
.stroke(
@EnesKaraosman
EnesKaraosman / PacMan_Animatable.swift
Created April 16, 2020 14:39
PacMan with Animatable Data
struct PacMan: Shape {
var endAngle: Angle
// SwiftUI bu parametre ile,
// gerekli optimizasyonu yapıyor.
var animatableData: Double {
get { endAngle.degrees }
set { endAngle = .degrees(newValue) }
}
struct ChatUser: Identifiable {
var id = UUID()
var userName: String
var avatar: UIImage?
}