There is the iPhone's name that can be looked up, and altered, by navigating to:
Settings > General > About > Name
How can a Swift application access this name? It is only the device name I seek, not the username.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
The need is to take pictures with Swift code settable parameters such as F-Stop, exposure time, and zoom level, in an iPhone 14 Pro.
What AVCam methods control these? If there are none, are there other ways to do this?
The option to have the torch constantly light on, or off, is also needed. Flash will not be used.
I have seen how to connect a button in a storyboard view to code that does its action by dragging that button into the assistant editor.
Now I need to do the opposite. There is a button in the storyboard view that is already connected to code. How can that existing already connected code be quickly looked up for a button?
The Storyboard Interface Builder has a Switch object that toggles between On, and Off, states. While in the On state it looks normal. While in the Off state it is grayed out.
I have a use for this object for the user to toggle between two options which are other than On, and Off. For my intended use its Off state gray out is undesirable. Is there way to prevent this switch graying out in its Off state?
I used the Interface Builder to place a Switch object in a view. I ctrl dragged it into the Assistant to make its handler a method of the class the view's is in, which is itself a subclass of "UITableViewController". A dialog box appear into which I entered the function name, and select the the option to have the sender as an argument.
The result is function of the form:
@IBAction func switchStateChange(_ sender: UISwitch) {
}
Now I need to query this Switch's On/Off state from elsewhere in the program, and if necessary change its state. It is not a good solution to save the sender parameter to a global variable because then it would require the user to change this switch's state before that global variable is set.
What is needed is to identify, and lookup, this switch object to access it from anywhere in the application. How is this done?
The need is to persist between launches the state of storyboard objects such as of type UISwitch, UITextField, etc. Can this be done using @AppStorage? If so how can @AppStorage be set to watch these?
I tried getting @AppStorage to watch an outlet class member variable that is connected to the storyboard object:
@IBOutlet weak var iPhoneName: UITextField!
@AppStorage("iPhoneName") var iPhoneName: String = ""
This got an error because the variable to be watched is already declared.
I decided to make the the watched variable different than the one connected to the Storyboard's UITextField object:
@AppStorage("iPhoneName") var striPhoneName: String = ""
and got the error: Unknown attribute 'AppStorage' . In what import library is @AppStorage defined?
If @AppStorage cannot be used for this, what is the easiest way to code storyboard object persistence? I am looking for an easy, and quick way. I am not concerned with memory usage right now.
Here is a code snippet by which I attempted to set a neutral white balance:
func prepare(completionHandler: @escaping (Error?) -> Void) {
func createCaptureSession() {
self.captureSession = AVCaptureSession()
}
func configureCaptureDevices() throws {
let session = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .back)
let cameras = (session.devices.compactMap { $0 })
if cameras.isEmpty {
throw CameraControllerError.noCamerasAvailable
}
for camera in cameras {
try camera.lockForConfiguration()
camera.setWhiteBalanceModeLocked(
with whiteBalanceGains: AVCaptureDevice.WhiteBalanceGains( redGain: 1.0, greenGain: 1.0, blueGain: 1.0),
completionHandler handler: ((CMTime) -> Void)? = nil
) // Errors: Extra arguments at positions #2, #3 in call, Cannot find 'with' in scope
camera.whiteBalanceMode = .locked
camera.unlockForConfiguration()
}catch{
// To Do: Error handling here
}
}
My call to "AVCaptureDevice.WhiteBalanceGains()" gets errors. What is the correct way to do this?
I do not know what I did to make it so, but somehow I accidentally got Xcode Interface Builder to display a storyboard file in an undesired mode which displays the UI buttons, and text fields, in rectangles as shown in the screenshot below. How do I reverse what I did to get it out of this mode?
The goal is to have the background, and foreground, colors show the current state of a UIButton on a storyboard file. The attempt to do that is done with this code:
var toggleLight: Bool = false
@IBAction func toggleLight(_ sender: UIButton) {
if( toggleLight ){
toggleLight = false
sender.baseBackgroundColor = UIColor.black
sender.baseForegroundColor = UIColor.white
}else{
toggleLight = true
sender.baseBackgroundColor = UIColor.white
sender.baseForegroundColor = UIColor.black
}
tableView.reloadData()
}
I get these errors:
Value of type 'UIButton' has no member 'baseBackgroundColor'
Value of type 'UIButton' has no member 'baseForegroundColor'
I do not understand this because in file "UIKit.UIButton" I see:
extension UIButton {
...
public var baseForegroundColor: UIColor?
public var baseBackgroundColor: UIColor?
...
}
What has gone wrong there?
I am not able drag a reference object from a Storyboard screen to code in the Assistant. The expected blue line appears as the screenshot shows, but no code is created in the Assistant. This reference object is not in the Launch Screen. When the the screen this object is in is highlighted, the correct file opens in the Assistant. Dragging this object from the "Content View" folder also does not work, even though the blue line also appears.
I was recently able to do this. Something changed. What might have changed?
I am attempting to follow this example of how to create a camera app:
https://www.appcoda.com/avfoundation-swift-guide/
It describes a sequence of 4 steps, and these steps are embodied in four functions:
func prepare(completionHandler: @escaping (Error?) -> Void) {
func createCaptureSession() { }
func configureCaptureDevices() throws { }
func configureDeviceInputs() throws { }
func configurePhotoOutput() throws { }
DispatchQueue(label: "prepare").async {
do {
createCaptureSession()
try configureCaptureDevices()
try configureDeviceInputs()
try configurePhotoOutput()
}
catch {
DispatchQueue.main.async {
completionHandler(error)
}
return
}
DispatchQueue.main.async {
completionHandler(nil)
}
}
}
What is confusing me is that it appears these four steps need to be executed sequentially, but in the Dispatch Queue they are executed simultaneously because .async is used. For example farther down that webpage the functions createCaptureSession(), and configureCaptureDevices(), and the others, are defined. In createCaptureSession() the member variables self.frontCamera, and self.rearCamera, are given values which are used in configureCaptureDevices(). So configureCaptureDevices() depends on createCaptureSession() having been already executed, something that it appears cannot be depended upon if both functions are executing simultaneously in separate threads.
What then is the benefit of using DispatchQueue()? How is it assured the above example dependencies are met?
What is the label parameter of the DispatchQueue()'s initializer used for?
I have a warning message that the method AVCapturePhotoOutput.dngPhotoDataRepresentation is deprecated. What has this method been superseded by?
I added a scene to an existing story board that already has other scenes. I put focus on the new scene, and in the Identity Inspector's "Class" field I gave it a class name. The "Storyboard ID" field did not show in this inspector. Why would it not?
No file named after the class name I gave it appeared in the "Project navigator". Is this supposed to happen automatically? Or must I create this Swift file that contains the class definition for the scene manually?
I have a UITextField object on a storyboard's scene. Its "Editing Did End" event is connected to the view controller's "actIPhoneName()" event handler method as shown in this screenshot.
I configured the keyboard to show its "Done" key. I expected that when this Done button is touched, that the keyboard would disappear, and the actIPhoneName() method would be called. But neither of these happen, nor does anything else. The UITextField object remains in edit mode. The breakpoint is never reached.
What must I do to make the Done keyboard key work to make the UITextField object lose its First Responder status, and call its "Editing Did End" event handler method?
I have a UITextField object in a storyboard's scene where the user is make numeric entries. Because this field is for numbers only I set the keyboard type to "Number Pad" in attributes. But this keyboard does not have a return key which leaves the user unable to signal when the entry is complete, the keyboard should be put away, and the entered value processed. I tried all the other numeric keyboards also, and found that none of them has a return key. The default keyboard does, but it is a full alphanumeric keyboard which is undesirable for that field.
How can I cause the return key, done key, or whichever does that function, appear on a numeric only keyboard?