This code to write UIImage data as heic works in iOS simulator with iOS < 17.5
import AVFoundation
import UIKit
extension UIImage {
public var heic: Data? { heic() }
public func heic(compressionQuality: CGFloat = 1) -> Data? {
let mutableData = NSMutableData()
guard let destination = CGImageDestinationCreateWithData(mutableData, AVFileType.heic as CFString, 1, nil),
let cgImage = cgImage else {
return nil
}
let options: NSDictionary = [
kCGImageDestinationLossyCompressionQuality: compressionQuality,
kCGImagePropertyOrientation: cgImageOrientation.rawValue,
]
CGImageDestinationAddImage(destination, cgImage, options)
guard CGImageDestinationFinalize(destination) else { return nil }
return mutableData as Data
}
public var isHeicSupported: Bool {
(CGImageDestinationCopyTypeIdentifiers() as! [String]).contains("public.heic")
}
var cgImageOrientation: CGImagePropertyOrientation { .init(imageOrientation) }
}
extension CGImagePropertyOrientation {
init(_ uiOrientation: UIImage.Orientation) {
switch uiOrientation {
case .up: self = .up
case .upMirrored: self = .upMirrored
case .down: self = .down
case .downMirrored: self = .downMirrored
case .left: self = .left
case .leftMirrored: self = .leftMirrored
case .right: self = .right
case .rightMirrored: self = .rightMirrored
@unknown default:
fatalError()
}
}
}
But with iOS 17.5 simulator it seems to be broken.
The call of CGImageDestinationFinalize
writes this error into the console:
writeImageAtIndex:962: *** CMPhotoCompressionSessionAddImage: err = kCMPhotoError_UnsupportedOperation [-16994] (codec: 'hvc1')
On physical devices it still seems to work.
Is there any known workaround for the iOS simulator?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
The code below renders a view with a navigation bar. A plus button is placed on the navigation bar which opens a sheet. After closing this sheet view programmatically the plus button of the first view won't react anymore. Is this an iOS bug or is the code incorrect?import SwiftUI
struct ContentView: View {
@State var isAddPresented = false
var body: some View {
NavigationView {
Text("Tap plus to add item")
.navigationBarTitle("Main Screen Title")
.navigationBarItems(trailing:
Button(action: {
self.isAddPresented = true
}) {
Image(systemName: "plus")
}
)
.sheet(isPresented: $isAddPresented,
onDismiss: {
self.isAddPresented = false
}) {
NavigationView {
Text("Tap on save")
.navigationBarTitle("Add something")
.navigationBarItems(leading: Button(action: {self.isAddPresented = false}, label: {Text("Save")}))
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I'm wondering which way I should go in my current app project.
It is an app where the user can take a photo and place multiple 2D vector images on that photo. Some vector images are showing angles between lines. The user can interact with the vectors to change the angels to make some measurements on the photo.
So you have multiple layers of vector images upon a photo. You can also pinch to zoom to have better control to set accurate vectors/angles.
The user can choose the layer to interact with so I need to have control of all gesture recognizers and for example deactivate the pinch gestures on the scroll view.
I'm wondering which technology I should use 🤔 SwiftUI, UIKit or CoreGraphics?
Does somebody have some recommendations?
I just created a SwiftUI project in Xcode 12.5 (12E262) and changed my main App class to
import SwiftUI
class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidFinishLaunching(_ application: UIApplication) {
print("applicationDidFinishLaunching")
}
func applicationDidBecomeActive(_ application: UIApplication) {
print("applicationDidBecomeActive")
}
func applicationDidEnterBackground(_ application: UIApplication) {
print("applicationDidEnterBackground")
}
func applicationWillEnterForeground(_ application: UIApplication) {
print("applicationWillEnterForeground")
}
func applicationWillTerminate(_ application: UIApplication) {
print("applicationWillTerminate")
}
}
@main
struct SwiftUIAppDelegateTestsApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
No app delegate method is called.
Should the App Delegate listed anywhere else e.g. in the build settings or info plist?
We created a view which is a bit comparable to the view of a contact in the iOS Contacts app. At the top there are input fields which can't be deleted and at the bottom is a long list of items which can be deleted.
I was wondering if is there a List with an ondelete() functionality but without separators?
I've created a view with a TextField and an EditButton. When I open this view in a fullScreenCover with the editMode active than the input text disappears when the Done-Button is tapped.
This behavior is appearing when a @ObservedObject is used. When a @State variable is used for the TextField then everything is fine.
This is the view
Swift
struct ProfileView: View {
@ObservedObject
var viewModel = ProfileViewModel()
@Environment(\.editMode) var editMode
@State
var name = ""
var body: some View {
VStack {
Text("@State")
TextField("TextField", text: $name)
.disabled(editMode?.wrappedValue == .inactive)
Text("@ObservedObject")
TextField("TextField", text: $viewModel.name)
.disabled(editMode?.wrappedValue == .inactive)
Spacer()
}
.padding()
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
}
}
}
Using
Swift
class ProfileViewModel: ObservableObject {
@Published var name: String = ""
}
This is the view which is presenting
Swift
struct ContentView: View {
@State
var isPresentingEmtpyProfile: Bool = false
var body: some View {
NavigationView {
List {
NavigationLink(destination: ProfileView()) {
Text("ProfileView")
}
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
isPresentingEmtpyProfile = true
}) {
Image(systemName: "plus")
}
}
}
.navigationBarTitle("Navigation", displayMode: .inline)
.fullScreenCover(isPresented: $isPresentingEmtpyProfile) {
NewProfileViewWithNavigation(isPresentingEmptyProfile: $isPresentingEmtpyProfile)
}
}
}
}
extension ContentView {
struct NewProfileViewWithNavigation: View {
@State
private var editMode = EditMode.active
@Binding
var isPresentingEmptyProfile: Bool
var body: some View {
NavigationView {
ProfileView()
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button(action: {
isPresentingEmptyProfile = false
}) {
Text("Close")
}
}
ToolbarItem(placement: .principal) {
Text("New Profile")
}
}
.environment(\.editMode, $editMode)
}
}
}
}
Does anyone have an idea why this is happening?