let names = ["John", "Jane", "Bob", "Alice"]
let lastNames = ["Doe", "Smith", "Johnson", "Williams"]
// Создаем третий массив, объединяя имена и фамилии в пары
var combinedArray = zip(names, lastNames).map { "\($0.0) \($0.1)" }
// Перемешиваем третий массив
combinedArray.shuffle()
// Выводим результат
print(combinedArray)
func savePhotoToCoreData(image: UIImage) {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
let managedContext = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "Photo", in: managedContext)!
let photo = NSManagedObject(entity: entity, insertInto: managedContext) as! Photo
if let imageData = image.pngData() {
photo.imageData = imageData
}
do {
try managedContext.save()
} catch let error as NSError {
print("Could not save. \(error), \(error.userInfo)")
}
}
func fetchPhotoFromCoreData() -> UIImage? {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return nil
}
let managedContext = appDelegate.persistentContainer.viewContext
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Photo")
do {
let results = try managedContext.fetch(fetchRequest) as! [Photo]
if let firstPhoto = results.first, let imageData = firstPhoto.imageData {
return UIImage(data: imageData)
} else {
return nil
}
} catch let error as NSError {
print("Could not fetch. \(error), \(error.userInfo)")
return nil
}
}
func showSimpleAlert() {
let alert = UIAlertController(title: "Sign out?", message: "You can always access your content by signing back in", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler: { _ in
//Cancel Action
}))
alert.addAction(UIAlertAction(title: "Sign out",
style: UIAlertActionStyle.default,
handler: {(_: UIAlertAction!) in
//Sign out action
}))
self.present(alert, animated: true, completion: nil)
}
func showSimpleActionSheet(controller: UIViewController) {
let alert = UIAlertController(title: "Title", message: "Please Select an Option", preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Approve", style: .default, handler: { (_) in
print("User click Approve button")
}))
alert.addAction(UIAlertAction(title: "Edit", style: .default, handler: { (_) in
print("User click Edit button")
}))
alert.addAction(UIAlertAction(title: "Delete", style: .destructive, handler: { (_) in
print("User click Delete button")
}))
alert.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler: { (_) in
print("User click Dismiss button")
}))
self.present(alert, animated: true, completion: {
print("completion block")
})
}