Swift is a powerful and intuitive programming language for Apple platforms and beyond.

Swift Documentation

Posts under Swift tag

2,384 results found
Sort by:
Post not yet marked as solved
109 Views

XCODE 13.0 is the worst delivery I have received from Apple (Bad Bugs)

The Simulator does not execute the code the last version 12 worked. I will not prepare my device the last version of 12 did. The code below worked on the simulator and real iPad Air 4th gen. 1.) I can not even get the iPad Air connected with nothing running on the iPad. 2.) The simulators can not run the CardView correctly. When going from isFaceUp true to false the back ground to not complete refresh in the simulator or active preview. The right top card works but it begins not the refresh the top of the card as it goes left on the screen and get worse when the cards on that are further down the screen. The Cards refresh less and less of the top of the card as it gets lower on the screen on the left half of the screen. Boarder shows properly but red does not completely always fill when completely when isFaceUp goes false for every card. The ones on the top left work but as you go down and left less of the top of the card fills in the "RoundedRectangle(cornerRadius: 20.0)" I guess the "LazyVGrid(columns: [GridItem(.adaptive(minimum: 68))])" fails to work properly. Do not plan to upgrade the iPad Air since I do not trust Apple code now! // //  ContentView.swift //  Memorize // //  Created by Reigh Jack on 8/19/21. //  using CS193P Spring 2021 // import SwiftUI struct ContentView: View {     var emojis = ["🚲", "🚂", "🚁", "🚜", "🚕" ,"🏎", "🚖", "🚐", "🚒", "✈️", "🚀", "⛵️", "🛸", "🛶", "🚌", "🏍", "🛺", "🚠", "🛵", "🚗", "🚚", "🚇", "🛻", "🚝"]     @State var emojiCount = 20     var body: some View {         VStack{             ScrollView {                 LazyVGrid(columns: [GridItem(.adaptive(minimum: 68))]) {                     ForEach(emojis[0..<emojiCount], id: .self ) { emoji in                         CardView(content: emoji)                             .aspectRatio( 2/3, contentMode: .fit)                     }                 }             }             .foregroundColor(.red)         }         .padding(.horizontal)     } } struct CardView: View {     var content: String     @State var isFaceUp: Bool = false          var body: some View {         ZStack{             let shape = RoundedRectangle(cornerRadius: 20.0)             if isFaceUp {                 shape.fill().foregroundColor(.white)                 shape.strokeBorder(lineWidth: 3)                 Text(content).font(.largeTitle)             } else {                 shape.fill()             }         }         .onTapGesture { isFaceUp = !isFaceUp }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()             .preferredColorScheme(.dark)         ContentView()             .preferredColorScheme(.light)   } }
Asked
by JackReigh.
Last updated
.
Post not yet marked as solved
30 Views

"Precondition failed: NSArray element failed to match the Swift Array Element type" error on iOS version < 13 but works fine on iOS 13 and 14.

I've got a class derived from UIView called ContentListView that goes like this: ContentListView source code It is used in the view controller like this: ContentsViewController source code But when I tried to run it on iOS 11 and 12 (both simulators and actual devices), it crashed. Although it worked on iOS 13 and 14. It crashed with this error: Precondition failed: NSArray element failed to match the Swift Array Element type Expected ContentListView but found UIView: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1001.0.82.4/swift/stdlib/public/core/ArrayBuffer.swift, line 346 2021-09-22 13:24:27.624568+0700 Kolibree[16970:513272] Precondition failed: NSArray element failed to match the Swift Array Element type Expected ContentListView but found UIView: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1001.0.82.4/swift/stdlib/public/core/ArrayBuffer.swift, line 346 The contentListViews in the storyboard themselves are of the type ContentListView so the error seems weird. How do I solve this? It has been days and I'm stuck at this. :( Thanks in advance.
Asked Last updated
.
Post not yet marked as solved
22 Views

How to open a view

(Swift, macOS, Storyboards) How to open a View with code and macOS? (a View, not a Window) I can open a Window Controller: var controller: NSWindowController? if controller == nil { let storyboard:NSStoryboard = NSStoryboard(name: "Main", bundle: nil) controller = storyboard.instantiateController(withIdentifier: "window1") as? NSWindowController } controller?.showWindow(self) But I could not figure out how to open a View Controller. What would the be equivalent code for a View Controller in macOS?
Asked Last updated
.
Post not yet marked as solved
15 Views

Simplest client server example code using IPC using XPC using swift on MacOS

I am from a C/C++, Python, Javascript background and recently started learning development on MacOS using Swift. I want simple IPC(Inter Process Communication) between two processes, let's call them server process and client process. I could not find any simple example showing use of XPC for IPC. Let me try to put my thinking and what I am trying to build. Suppose I have server_process.swift // This is XPC Server import Foundation func run_server_loop() {     // I guess I have to use NSXPCListener e.g. XPC Service } func on_message(message) {     // I have received message from client_server.swift     // do whatever can be done with this message     // send reply to client_server.swift     if(message == "ping") {         send("pong")     } else {         send("command not supported")     } } // run loop to start listener run_server_loop() I would need client_server.swift import Foundation // This is XPC Client func some_way_to_connect() {     // some way to connect to server process } // connect to server which is running on server_process.swift client = some_way_to_connect() // send a message to server client.send("ping") I put my thoughts in pseudo code. How can I achieve such communication using XPC using Swift?
Asked
by alokmahor.
Last updated
.
Post not yet marked as solved
22 Views

Image Colour Reflect UI Background Colour?

Anyone know how Apple manages to make the UI colour the same as the Image or another object colour? Like overall I think this is a really cool fun effect I'd love to play with this effect some somehow Heres an example with how the New Safari does it with the page colour but I see it with other Apple apps like the music Player app for example.
Asked
by ellj69.
Last updated
.
Post not yet marked as solved
103 Views

Xcode 13 - warning: Could not read serialized diagnostics file: error("Invalid diagnostics signature")

I just updated to xcode 13 but when i try to compile im getting this error: warning: Could not read serialized diagnostics file: error("Invalid diagnostics signature")  And also i dont know if its part of the same but then it cant find some frameworks. Cannot find type 'CLLocation' in scope thanks
Asked Last updated
.
Post not yet marked as solved
13k Views

Invalid code signature problem with Xcode12

I'm practicing a swift 5 class, and have this issue: Could not launch “I AM RICH” Domain: IDEDebugSessionErrorDomain Code: 3 Failure Reason: The operation couldn’t be completed. Unable to launch com.superdie.I-AM-RICH because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user. User Info: {     DVTRadarComponentKey = 855031;     RawLLDBErrorMessage = "The operation couldn\U2019t be completed. Unable to launch com.superdie.I-AM-RICH because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user."; } I'm not sure what can I do, some help would be nice :)
Asked
by Rimbaud.
Last updated
.
Post not yet marked as solved
47 Views

Can't interpolate a Bool in SwiftUI Text?

Simple code like this gives an error. struct MyView: View {     @State private var test: Bool = false     var body: some View {           Text("Hello. \(test)") The error: Instance method 'appendInterpolation(_:formatter:)' requires that 'Bool' inherit from 'NSObject' What is going on?
Asked
by rnikander.
Last updated
.
Post not yet marked as solved
40 Views

iOS App Create Custom Calendar prompt dilemma

Hi all, I'm writing an iOS app for the iPhone and iPad and it's basically done. I'm going through lots of regression testing and I'm sort of stuck on a scenario that I'm not sure of the most elegant way to handle it. My app uses a custom calendar, EKCalendar, for my users to do scheduling. When the user first launches the app, it prompts the user to enter a custom calendar name. I don't want them to default to the standard apple Calendar because it will mix appointments with my app when I display their appointments for this app. Should I force them to enter a custom calendar name or should I allow them to just default to the 'Calendar' for their scheduling? And then maybe down the road offer an update where they can change this custom calendar name as I am storing it using CoreData.
Asked
by Pete4Dev.
Last updated
.
Post not yet marked as solved
43 Views

Crash in UITableview cellforrow in iOS 15 beta

Hello, Crash on reload tableview in ios 15. Crashed: com.apple.main-thread EXC_BREAKPOINT 0x0000000104a37628 keyboard_arrow_up arrow_right 0 GuardsPro ShiftsListViewController.swift - Line 263 ShiftsListViewController.tableView(:cellForRowAt:) + 263 1 GuardsPro - Line 4345689852 @objc ShiftsListViewController.tableView(:cellForRowAt:) + 4345689852 2 UIKitCore -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 1536 3 UIKitCore -[UITableView _updateVisibleCellsForRanges:createIfNecessary:] + 748 4 UIKitCore -[UITableView _updateVisibleCellsNow:] + 1396 5 UIKitCore -[UITableView layoutSubviews] + 456 6 UIKitCore -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2620 7 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*) + 536 8 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 144 9 QuartzCore CA::Context::commit_transaction(CA::Transaction*, double, double*) + 500 10 QuartzCore CA::Transaction::commit() + 680 11 QuartzCore CA::Transaction::flush_as_runloop_observer(bool) + 100 12 UIKitCore _UIApplicationFlushCATransaction + 76 13 UIKitCore _UIUpdateSequenceRun + 84 14 UIKitCore schedulerStepScheduledMainSection + 144 15 UIKitCore runloopSourceCallback + 60 16 CoreFoundation CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28 17 CoreFoundation __CFRunLoopDoSource0 + 208 18 CoreFoundation __CFRunLoopDoSources0 + 268 19 CoreFoundation __CFRunLoopRun + 820 20 CoreFoundation CFRunLoopRunSpecific + 600 21 GraphicsServices GSEventRunModal + 164 22 UIKitCore -[UIApplication _run] + 1100 23 UIKitCore UIApplicationMain + 2124 24 GuardsPro AppDelegate.swift - Line 21 main + 21
Asked
by sspogra.
Last updated
.
Post not yet marked as solved
37 Views

Type 'VNRecognizedPointKey' has no member 'thumbTip'

With the release of Xcode 13, a large section of my vision framework processing code became errors and cannot compile. All of these have became deprecated. This is my original code:  do {       // Perform VNDetectHumanHandPoseRequest       try handler.perform([handPoseRequest])       // Continue only when a hand was detected in the frame.       // Since we set the maximumHandCount property of the request to 1, there will be at most one observation.       guard let observation = handPoseRequest.results?.first else {         self.state = "no hand"         return       }       // Get points for thumb and index finger.       let thumbPoints = try observation.recognizedPoints(forGroupKey: .handLandmarkRegionKeyThumb)       let indexFingerPoints = try observation.recognizedPoints(forGroupKey: .handLandmarkRegionKeyIndexFinger)       let middleFingerPoints = try observation.recognizedPoints(forGroupKey: .handLandmarkRegionKeyMiddleFinger)       let ringFingerPoints = try observation.recognizedPoints(forGroupKey: .handLandmarkRegionKeyRingFinger)       let littleFingerPoints = try observation.recognizedPoints(forGroupKey: .handLandmarkRegionKeyLittleFinger)       let wristPoints = try observation.recognizedPoints(forGroupKey: .all)               // Look for tip points.       guard let thumbTipPoint = thumbPoints[.handLandmarkKeyThumbTIP],          let thumbIpPoint = thumbPoints[.handLandmarkKeyThumbIP],          let thumbMpPoint = thumbPoints[.handLandmarkKeyThumbMP],          let thumbCMCPoint = thumbPoints[.handLandmarkKeyThumbCMC] else {         self.state = "no tip"         return       }               guard let indexTipPoint = indexFingerPoints[.handLandmarkKeyIndexTIP],          let indexDipPoint = indexFingerPoints[.handLandmarkKeyIndexDIP],          let indexPipPoint = indexFingerPoints[.handLandmarkKeyIndexPIP],          let indexMcpPoint = indexFingerPoints[.handLandmarkKeyIndexMCP] else {         self.state = "no index"         return       }               guard let middleTipPoint = middleFingerPoints[.handLandmarkKeyMiddleTIP],          let middleDipPoint = middleFingerPoints[.handLandmarkKeyMiddleDIP],          let middlePipPoint = middleFingerPoints[.handLandmarkKeyMiddlePIP],          let middleMcpPoint = middleFingerPoints[.handLandmarkKeyMiddleMCP] else {         self.state = "no middle"         return       }               guard let ringTipPoint = ringFingerPoints[.handLandmarkKeyRingTIP],          let ringDipPoint = ringFingerPoints[.handLandmarkKeyRingDIP],          let ringPipPoint = ringFingerPoints[.handLandmarkKeyRingPIP],          let ringMcpPoint = ringFingerPoints[.handLandmarkKeyRingMCP] else {         self.state = "no ring"         return       }               guard let littleTipPoint = littleFingerPoints[.handLandmarkKeyLittleTIP],          let littleDipPoint = littleFingerPoints[.handLandmarkKeyLittleDIP],          let littlePipPoint = littleFingerPoints[.handLandmarkKeyLittlePIP],          let littleMcpPoint = littleFingerPoints[.handLandmarkKeyLittleMCP] else {         self.state = "no little"         return       }               guard let wristPoint = wristPoints[.handLandmarkKeyWrist] else {         self.state = "no wrist"         return       } ... } Now every line from thumbPoints onwards results in error, I have fixed the first part (not sure if it is correct or not as it cannot compile) to :         let thumbPoints = try observation.recognizedPoints(forGroupKey: VNHumanHandPoseObservation.JointsGroupName.thumb.rawValue)        let indexFingerPoints = try observation.recognizedPoints(forGroupKey: VNHumanHandPoseObservation.JointsGroupName.indexFinger.rawValue)        let middleFingerPoints = try observation.recognizedPoints(forGroupKey: VNHumanHandPoseObservation.JointsGroupName.middleFinger.rawValue)        let ringFingerPoints = try observation.recognizedPoints(forGroupKey: VNHumanHandPoseObservation.JointsGroupName.ringFinger.rawValue)        let littleFingerPoints = try observation.recognizedPoints(forGroupKey: VNHumanHandPoseObservation.JointsGroupName.littleFinger.rawValue)        let wristPoints = try observation.recognizedPoints(forGroupKey: VNHumanHandPoseObservation.JointsGroupName.littleFinger.rawValue) I tried many different things but just could not get the retrieving individual points to work. Can anyone help on fixing this?
Asked Last updated
.
Post not yet marked as solved
29 Views

Cannot interpret crashlog _assertionFailure

Thread 9 name: Thread 9 Crashed: 0 libswiftCore.dylib 0x0000000188d21398 _assertionFailure(_:_:file:line:flags:) + 1504 (AssertCommon.swift:132) 1 libswiftFoundation.dylib 0x0000000188c8beec specialized static Int32._forceBridgeFromObjectiveC(_:result:) + 372 (NSNumber.swift:207) 2 HaishinKit 0x0000000102fbe46c VideoIOComponent.attachScreen(_:useScreenSize:) + 496 (&lt;compiler-generated&gt;:0) 3 HaishinKit 0x0000000102f7e188 closure #1 in NetStream.attachScreen(_:useScreenSize:) + 156 (NetStream+Extension.swift:18) 4 HaishinKit 0x0000000102f2ff7c thunk for @escaping @callee_guaranteed () -&gt; () + 20 (&lt;compiler-generated&gt;:0) 5 libdispatch.dylib 0x0000000184fbf2b0 _dispatch_call_block_and_release + 24 (init.c:1466) 6 libdispatch.dylib 0x0000000184fc0298 _dispatch_client_callout + 16 (object.m:559) 7 libdispatch.dylib 0x0000000184f9c344 _dispatch_lane_serial_drain$VARIANT$armv81 + 568 (inline_internal.h:2557) 8 libdispatch.dylib 0x0000000184f9ce2c _dispatch_lane_invoke$VARIANT$armv81 + 400 (queue.c:3862) 9 libdispatch.dylib 0x0000000184fa666c _dispatch_workloop_worker_thread + 692 (queue.c:6589) 10 libsystem_pthread.dylib 0x00000001cd8bd5bc _pthread_wqthread + 272 (pthread.c:2436) 11 libsystem_pthread.dylib 0x00000001cd8c086c start_wqthread + 8 Thread 10: 0 libsystem_pthread.dylib 0x00000001cd8c0864 _pthread_dependency_fulfill_slow + 192 (pthread_dependency.c:57) Thread 11: 0 libsystem_pthread.dylib 0x00000001cd8c0864 _pthread_dependency_fulfill_slow + 192 (pthread_dependency.c:57) Thread 9 crashed with ARM Thread State (64-bit): x0: 0x0000000282abc480 x1: 0x0000000188fe7840 x2: 0x0000000000000007 x3: 0x0000000193edad18 x4: 0x0000000000000000 x5: 0x000000016da46630 x6: 0x0000000000000032 x7: 0x000000000000003e x8: 0x0000000282abc488 x9: 0xfffffffe00000000 x10: 0x0000000200000003 x11: 0x0000000000000001 x12: 0x0000000000000003 x13: 0x000000009740682d x14: 0x0000000097607000 x15: 0x0000000000007000 x16: 0x0000000017600000 x17: 0x02000001000001f8 x18: 0x0000000000000000 x19: 0x0000000282abc480 x20: 0x000000016da466c0 x21: 0x0000000188cd5688 x22: 0x0000000000000019 x23: 0x0000000000000000 x24: 0x00000000000000cf x25: 0x000000000000000b x26: 0x0000000000000002 x27: 0x0000000188cd6040 x28: 0x000000016da46700 fp: 0x000000016da467b0 lr: 0x0000000188d21398 sp: 0x000000016da46700 pc: 0x0000000188d21398 cpsr: 0x60000000 esr: 0xf2000001 Address size fault When the app try to live stream on Youtube, this crash occur. Only some device experience this crash. Thank you in advance! Tenna
Asked
by tenna.
Last updated
.
Post not yet marked as solved
37 Views

Any use of keyboard crashing app after upgrading to Xcode 13

Every UITextview or UITextfield in my app crashes now after upgrading to Xcode 13.0 Here is the crash: and here is the trace: I put a breakpoint on every call to stringByTrimmingCharacteresInSet and it shows nothing. This bug is a result of updating Xcode. Any help would be very appreciated!
Asked Last updated
.
Post not yet marked as solved
440 Views

Associated Code?

When showing an ImageDownloader actor, the presenter said a solution on avoiding duplicate downloads is shown with the code associated with this video. When will this code be available? I don't see it on the video page.
Asked
by MegaWatt.
Last updated
.
Post not yet marked as solved
30k Views

Xcode error: Abort Trap 6

Occasionally, I get this error and I tried to research it but I couldnt figure out how to solve it. It says:1. While deserializing SIL vtable for 'PostTextCVC' in module 'Appp' error: Abort trap: 6The only way to dismiss this is to user another simulator or my actual phone. I don't know how to fix it for real though, don't even know what that error means. It's not exactly descriptive. Any suggestions?PS: Xcode version 10.0. beta 5
Asked
by breakeven.
Last updated
.