Skip to content

Instantly share code, notes, and snippets.

let gradientStart = Color(red: 239.0 / 255, green: 120.0 / 255, blue: 221.0 / 255)
let gradientStartDark = Color(red: 95.0 / 255, green: 169.0 / 255, blue: 244.0 / 255)
let gradientEnd = Color(red: 239.0 / 255, green: 172.0 / 255, blue: 120.0 / 255)
let gradientEndDark = Color(red: 79.0 / 255, green: 178.0 / 255, blue: 141.0 / 255)
let toggleTextcolorLight = Color(red: 227.0 / 255, green: 227.0 / 255, blue: 227.0 / 255)
let toggleTextcolorDark = Color(red: 34.0 / 255, green: 38.0 / 255, blue: 58.0 / 255)
let textColorDark = Color(red: 238.0 / 255, green: 238.0 / 255, blue: 238.0 / 255)
import SwiftUI
struct ContentView: View {
@Environment(\.colorScheme) var colorScheme
var body: some View {
ZStack {
ZStack(alignment: .top) {
ShapeView().offset(x: -80, y : -389).shadow(radius: 12)
}
VStack {
struct ContactInfo : Identifiable{
var id = UUID()
var firstName: String
var lastName: String
var phoneNumber: CNPhoneNumber?
}
import Contacts
class FetchContacts {
func fetchingContacts() -> [ContactInfo]{
var contacts = [ContactInfo]()
let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey]
let request = CNContactFetchRequest(keysToFetch: keys as [CNKeyDescriptor])
do {
try CNContactStore().enumerateContacts(with: request, usingBlock: { (contact, stopPointer) in
contacts.append(ContactInfo(firstName: contact.givenName, lastName: contact.familyName, phoneNumber: contact.phoneNumbers.first?.value))
extension UIApplication {
func endEditing(_ force: Bool) {
self.windows
.filter{$0.isKeyWindow}
.first?
.endEditing(force)
}
}
struct ContactRow: View {
var contact: ContactInfo
var body: some View {
Text("\(contact.firstName) \(contact.lastName)").foregroundColor(.primary)
}
}
@State private var contacts = [ContactInfo.init(firstName: "", lastName: "", phoneNumber: nil)]
@State private var searchText = ""
@State private var showCancelButton: Bool = false
func getContacts() {
DispatchQueue.main.async {
self.contacts = FetchContacts().fetchingContacts()
}
}
}
func requestAccess() {
let store = CNContactStore()
switch CNContactStore.authorizationStatus(for: .contacts) {
case .authorized:
self.getContacts()
case .denied:
store.requestAccess(for: .contacts) { granted, error in
if granted {
self.getContacts()
}
// Search view
HStack {
HStack {
//search bar magnifying glass image
Image(systemName: "magnifyingglass").foregroundColor(.secondary)
//search bar text field
TextField("search", text: self.$searchText, onEditingChanged: { isEditing in
self.showCancelButton = true
})