Skip to content

Instantly share code, notes, and snippets.

View maniyarpayal's full-sized avatar

Payal Maniyar maniyarpayal

View GitHub Profile
extension String.StringInterpolation {
mutating func appendInterpolation(_ values: [String], empty defaultValue: @autoclosure () -> String) {
if values.count == 0 {
appendLiteral(defaultValue())
} else {
appendLiteral(values.joined(separator: ", "))
}
}
}
func EmptyMsg () -> String {
extension String.StringInterpolation {
mutating func appendInterpolation(repeat str: String, _ count: Int) {
for _ in 0 ..< count {
appendLiteral(str)
}
}
}
print("\(repeat: "Do what you like\n ", 6)")
import Foundation
extension String.StringInterpolation {
mutating func appendInterpolation(_ number: Int, style: NumberFormatter.Style) {
let formatter = NumberFormatter()
formatter.numberStyle = style
if let result = formatter.string(from: number as NSNumber) {
appendLiteral(result)
class User {
var firstName: String
var lastName: String
init (firstName: String,lastName: String){
self.firstName = firstName
self.lastName = lastName
}
}
//StringInterpolation 1
class Point {
let x: Int, y: Int
init( x: Int, y: Int){
self.x = x
self.y = y
}
}
let p = Point(x: 21, y: 30)
print(p)
class Point {
let x: Int, y: Int
init( x: Int, y: Int){
self.x = x
self.y = y
}
}
let p = Point(x: 21, y: 30)
print(p)
@maniyarpayal
maniyarpayal / structprint.playground
Last active April 16, 2019 09:49
print of struct
struct AppUser{
var firstName: String
var lastName: String
}
let appUser = AppUser(firstName : "Payal", lastName : "Maniyar")
print("User details: \(appUser)")
Output :
@maniyarpayal
maniyarpayal / Date.playground
Created June 22, 2018 12:24
Set notification
//: Playground - noun: a place where people can play
import UIKit
import UserNotifications
var str = "Hello, playground"
var calendar = Calendar.current
calendar.timeZone = TimeZone.current
var dateFormat = DateFormatter()
dateFormat.dateFormat = "dd MMM yyyy"
@maniyarpayal
maniyarpayal / MessageFilterExtension.swift
Last active May 11, 2018 11:40
Message Filter Extension Code
//
// MessageFilterExtension.swift
// SMS Filter Demo
//
// Created by Dhanashree Inc on 11/05/18.
// Copyright © 2018 Dhanashree Inc. All rights reserved.
//
import IdentityLookup
@maniyarpayal
maniyarpayal / codeble.playground
Created March 13, 2018 11:01
Codeble playground Code
//: Playground - noun: a place where people can play
import UIKit
struct Photo: Codable
{
//String, URL, Bool and Date conform to Codable.
var title: String
var url: URL
var isSample: Bool