class Service: UIViewController {
static func showError(_ message:String) {
// Create new Alert
let dialogMessage = UIAlertController(title: "Error", message: message, preferredStyle: .alert)
// Create OK button with action handler
let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
print("Ok button tapped")
})
//Add OK button to a dialog message
dialogMessage.addAction(ok)
// Present Alert to
self.present(dialogMessage , animated: true, completion: nil)
}
}
why i get error in this line:
self.present(dialogMessage , animated: true, completion: nil)
the error:
Instance member 'present' cannot be used on type 'Service'
why?
Post
Replies
Boosts
Views
Activity
I made an extension to UIViewController and inside i have function I use several times:
extension UIViewController {
func transitionToHomeVC() {
let homeViewController = self.storyboard?.instantiateViewController(withIdentifier: NameConstants.StoryBoard.homeViewController) as? HomeViewController
self.view.window?.rootViewController = homeViewController
self.view.window?.makeKeyAndVisible()
}
}
And I have a registration button and as soon as you click if the information was received and correct and etc ... then he has to move me at the to the HomeViewController screen and he does not do it.
He does all the actions but does not pass to screen.
@IBAction func signUpTapped(_ sender: Any) {
// Validate the fields
let error = validDataFields()
if error != nil {
// There's something wrong with the fields, show error message
Service.showError(vc: self, message: error!)
}
else {
// Create cleaned versions of the data
let fireName = firstNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let lastName = lastNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let email = emailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let password = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
// Create the user
Auth.auth().createUser(withEmail: email, password: password) { resulte, err in
// Check for errors
if err != nil {
// There was an error creating the user
Service.showError(vc: self, message: "Error creating user \n make sure you enter: \n current email")
}
else {
// User was created successfully, now store the first name and last name
let db = Firestore.firestore()
db.collection("users").addDocument(data: ["firstName":fireName,"lastName":lastName, "uid": resulte!.user.uid]) { error in
if error != nil {
// Show error message
Service.showError(vc: self, message: " Error saving user Data")
}
}
self.transitionToHomeVC()
}
}
}
}
why it not move to homeViewController?
I know there is a problem with this.
But I still ask if this is possible to develop call recording in swift?
how i can convert my xcode project to ipa?
i read all the methods but it very old (all methods for xcode 9) and not working..
what i can do?
i have this code:
https://stackoverflow.com/a/50999497/19364094
and when i try to call func showCallAlert() from another ViewController it it not working for me and it not detect if user click call or cancel
what it can do?
why when i Swipe the table view the swipe not disappear?
see screenshot
It just gets stuck like that and won't come back, why?
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let item = realArray[indexPath.row]
let callAction = UIContextualAction(style: .normal, title: "Call Private", handler: { (action, view, success) in
self.service.dialNumber(number: item.telephone, prefixNumber: true)
self.service.setupCallerId(firstName: item.firstName, lastName: item.lastName, telephone: item.telephone)
})
callAction.backgroundColor = .systemGreen
let configuration = UISwipeActionsConfiguration(actions: [callAction])
return configuration
}
i created a list with colors and i want when the user click red so all the screen was background red, if user click green so full background is green...
i don't know why but the var not change..
var body: some View {
NavigationView {
List {
Section {
ScreenColorButtons(text: "Red", color: .red)
ScreenColorButtons(text: "Green", color: .green)
ScreenColorButtons(text: "Blue", color: .blue)
}
}
}
}
}
struct ScreenColorButtons: View {
@State static var screenSelected: Color = Color.red
var text: String
var color: Color
var body: some View{
Button(action: {
ScreenColorButtons.screenSelected = color
print(ScreenColorButtons.screenSelected)
}, label: {
NavigationLink(text){}
})
}
}
the ScreenColorView:
struct ScreenColorView: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
Color.ScreenColorButtons.screenSelected
}
}
why the var not change and error to background??? thank for answer
i have NavigationView in my code
i do this for button it Navigation
Button{
print("")
}label: {
Image(systemName: "list.dash")
.foregroundColor(.gray)
}
}
how i can navigate to another view when user click the button??
why the setTorchModeOn not working? it not change the level torch
guard let device = AVCaptureDevice.default(for: .video) else { return }
if device.hasTorch {
do {
try device.lockForConfiguration()
try device.setTorchModeOn(level: 0.1)
if on == true {
device.torchMode = .on
} else {
device.torchMode = .off
}
device.unlockForConfiguration()
} catch {
print("Torch could not be used")
}
} else {
print("Torch is not available")
}
}
i maked core data and i fetch all data to List.
all working (add ,delete) but! if the app inactive (to background) and i open again to delete a row it crashes with error:
"Thread 1: "An NSManagedObjectContext cannot delete objects in other contexts."
struct HistoryView: View {
@State private var history: [HistoryList] = [HistoryList]()
let coreDM: CoreDataManager
var dateFormatter: DateFormatter {
let formatter = DateFormatter()
formatter.dateFormat = "MM-dd-yyyy HH:mm"
return formatter
}
private func populateHistory(){
history = coreDM.getAllHistory()
}
var body: some View {
NavigationView{
VStack {
if !history.isEmpty {
List {
ForEach(history, id: \.self) { historyList in
HStack {
Text(dateFormatter.string(from: historyList.dateFlash ?? Date(timeIntervalSinceReferenceDate: 0)))
Text("\(historyList.timerFlash)s")
.multilineTextAlignment(.trailing)
.frame(maxWidth: .infinity, alignment: .trailing)
}
}.onDelete(perform: { indexset in
indexset.forEach { index in
let history = history[index]
coreDM.deleteHistory(history: history)
populateHistory()
}
})
}.refreshable {
populateHistory()
print("## Refresh History List")
}
} else {
Text("History Flashlight is Empty")
}
}
.onAppear {
populateHistory()
print("OnAppear")
}
}.navigationTitle("History Flashlight")
.navigationBarTitleDisplayMode(.inline)
}
}
struct HistoryView_Previews: PreviewProvider {
static var previews: some View {
HistoryView(coreDM: CoreDataManager())
}
}
why?
how i make a List like at swiftui at storyboard?
the UITableView not the same..
look image:
https://i.ibb.co/Qn69TRR/Untitled.png
how i can do List like a swiftui in storyboard?
I have the code:
if let url = URL(string:"tel://\(String(describing: Util.checkForNullString(contactNo)))"), UIApplication.shared.canOpenURL(url){
if #available(iOS 10, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
}
how I can detected if user calling or dismiss?
How i can open Location services direct to my app?
I want it to go to the screen where the user chooses allow location or not can be enabled in the app..
UIApplication.shared.open(URL(string: "App-prefs:LOCATION_SERVICES")!)
this code open for me only the location services but how i can open location setting to my app?
i have coredata and i want to add bool Optional but i get error:
import CoreData
@objc(HistoryData)
class HistoryData: NSManagedObject {
@NSManaged var firstName: String
@NSManaged var lastName: String
@NSManaged var telephone: String
@NSManaged var time: String
@NSManaged var callHidden: Bool? // Here the error
}
Error:
Property cannot be marked @NSManaged because its type cannot be represented in Objective-C
in xcdatamodeld it selected Optional but it not do it..
why?
i do this code:
struct TextView: View {
@ObservedObject var service = Service()
@State private var text: String = ""
@FocusState var isInputActive: Bool
var body: some View {
ZStack{
Color(red: 242 / 255, green: 242 / 255, blue: 247 / 255)
.edgesIgnoringSafeArea(.top)
VStack {
Text("QRCode Text")
.multilineTextAlignment(.center)
.font(.system(size: 30, weight: .heavy, design: .default))
.padding(.top, 16.0)
TextField("Enter Text", text: $text)
.textFieldStyle(RoundedBorderTextFieldStyle())
.border(Color.white)
.fixedSize(horizontal: false, vertical: true)
.multilineTextAlignment(.center)
.padding()
.frame(width: 350, height: 80)
.background(Rectangle().fill(Color.white).shadow(radius: 20))
.cornerRadius(30)
.frame(height: 100)
.focused($isInputActive)
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()
Button("Done") {
isInputActive = false
}
}
}
Image(uiImage: service.generateQRCode(from: "\(text)"))
.interpolation(.none)
.resizable()
.padding(2.0)
.scaledToFill()
.frame(width: 250, height: 250)
.fixedSize(horizontal: false, vertical: true)
.multilineTextAlignment(.center)
.frame(width: 350, height: 350)
.background(Rectangle().fill(Color.white).shadow(radius: 20))
.cornerRadius(30)
Button("Save QRCode") {
print("save")
}
.padding(.vertical, 10.0)
.padding(.horizontal, 100.0)
.background(Color.blue)
.cornerRadius(20)
.foregroundColor(Color.white)
.frame(height: 100)
Spacer()
}
}
}
}
and when i click on textfield and keyboard up, it up all view, why?