Posts

Post marked as solved
1 Replies
763 Views
I want to use emoji like this in my iOS app and release it on the App Store. struct ContentView: View { @State private var move = false var body: some View { VStack { Text("👻") .font(.largeTitle) .position(x: move ? 50 : 400) Button("Move") { withAnimation(.linear(duration: 2)) { move.toggle() } } } } } Are there any other problems with this?(like legal issues, etc.)
Posted Last updated
.
Post marked as solved
2 Replies
438 Views
I prefer the coding style below. (Of course, the code below is not long, but when the number of lines is long) struct ContentView: View { var body: some View { VStack { text hello } } var text: some View { Text("text") .padding() } var hello: some View { Button("hello") { print("hello") } } } But people seem to prefer the style below.(Not only when the number of lines of code is small, but also when it is long) struct ContentView: View { var body: some View { VStack { Text("text") .padding() Button("hello") { print("hello") } } } } Which coding style is more popular among the two?
Posted Last updated
.
Post not yet marked as solved
0 Replies
421 Views
This code works fine. struct Cardify: AnimatableModifier { init(isFaceUp: Bool) { rotation = isFaceUp ? 0 : 180 } var animatableData: Double { get { rotation } set { rotation = newValue } } var rotation: Double func body(content: Content) -> some View { ZStack { let shape = RoundedRectangle(cornerRadius: DrawingConstants.cornerRadius) if rotation < 90 { shape.fill().foregroundColor(.white) shape.strokeBorder(lineWidth: DrawingConstants.lineWidth) } else { shape.fill() } content .opacity(rotation < 90 ? 1 : 0) } .rotation3DEffect(Angle.degrees(rotation), axis: (0, 1, 0)) } private struct DrawingConstants { static let cornerRadius: CGFloat = 10 static let lineWidth: CGFloat = 3 } } But the code below where I changed AnimatableModifier to Animatable, ViewModifier doesn't work. struct Cardify: Animatable, ViewModifier { init(isFaceUp: Bool) { rotation = isFaceUp ? 0 : 180 } var animatableData: Double { get { rotation } set { rotation = newValue } } var rotation: Double func body(content: Content) -> some View { ZStack { let shape = RoundedRectangle(cornerRadius: DrawingConstants.cornerRadius) if rotation < 90 { shape.fill().foregroundColor(.white) shape.strokeBorder(lineWidth: DrawingConstants.lineWidth) } else { shape.fill() } content .opacity(rotation < 90 ? 1 : 0) } .rotation3DEffect(Angle.degrees(rotation), axis: (0, 1, 0)) } private struct DrawingConstants { static let cornerRadius: CGFloat = 10 static let lineWidth: CGFloat = 3 } } how do i fix it?
Posted Last updated
.
Post not yet marked as solved
2 Replies
480 Views
I watched Stanford 193p, and I had a question. When the professor writes the code, he writes like this struct GameView: View { var body: some View { gameBody } var gameBody: some View { Button("gameBody") { gameBodyFunc() } } private func gameBodyFunc() { } } Why is the function declared private but not the gameBody variable? I am impressed with his coding style and want to learn it.
Posted Last updated
.
Post not yet marked as solved
0 Replies
938 Views
that is my python code (file name pythonTest.py) while True: a = input() print(a) I want to run this python code in a swift script and get the result. For example, I would like to enter something command like this. python3 pythonTest.py\n1\n2\n3\n and ctrl + C i found Process() but this is only entered once and I don't know how to handle input(), ctrl + C How can I do that? If it's not possible in Swift, is it possible in Python?
Posted Last updated
.
Post marked as solved
3 Replies
1.3k Views
my code func placeObjectAtImageTracking(object: ModelEntity, imageAnchor: ARImageAnchor) -> AnchorEntity {     let imageAnchorEntity = AnchorEntity(anchor: imageAnchor) return imageAnchorEntity } in this code, AnchorEntity(anchor: imageAnchor) is occuring error when i changed xcode setting device. It's fine when I set it to my real phone, but when I change it to the simulator, the following error appears. No exact matches in call to initializer  how to solve it?
Posted Last updated
.
Post not yet marked as solved
0 Replies
1.3k Views
i use this code in my app // MARK: - Protocol protocol VideoManagerProtocol: AnyObject {   func didReceive(sampleBuffer: CMSampleBuffer) } final class VideoManager: NSObject {       // MARK: -- Properties       /// RequestPermissionCompletionHandler   typealias RequestPermissionCompletionHandler = ((_ accessGranted: Bool) -> Void)       /// delegate of VideoManager   weak var delegate: VideoManagerProtocol?       /// An object that manages capture activity.   let captureSession = AVCaptureSession()       /// A device that provides input (such as audio or video) for capture sessions. //  let videoDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front) // choose deviceType, position is better but don't know ipad camera so choose default saftely   let videoDevice = AVCaptureDevice.default(for: .video)   /// A Core Animation layer that displays the video as it’s captured.   lazy var videoLayer: AVCaptureVideoPreviewLayer = {     return AVCaptureVideoPreviewLayer(session: captureSession)   }()       /// A capture output that records video and provides access to video frames for processing.   lazy var videoOutput: AVCaptureVideoDataOutput = {     let output = AVCaptureVideoDataOutput()     let queue = DispatchQueue(label: "VideoOutput", attributes: DispatchQueue.Attributes.concurrent, autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency.inherit)     output.setSampleBufferDelegate(self, queue: queue)     output.alwaysDiscardsLateVideoFrames = true     return output   }()       // MARK: -- Methods   override init() {     guard let videoDevice = videoDevice, let videoInput = try? AVCaptureDeviceInput(device: videoDevice) else {       fatalError("No `Video Device` detected!")     }           super.init()           captureSession.addInput(videoInput)     captureSession.addOutput(videoOutput)   }       func startVideoCapturing() {     self.captureSession.startRunning() // do not operate in dispatch global background //    DispatchQueue.global(qos: .background).async { //      self.captureSession.startRunning() //    }   }       func stopVideoCapturing() {     captureSession.stopRunning()   }       func requestPermission(completion: @escaping RequestPermissionCompletionHandler) {     AVCaptureDevice.requestAccess(for: .video) { (accessGranted) in       completion(accessGranted)     }   } } extension VideoManager {     } // MARK: - AVCaptureVideoDataOutputSampleBufferDelegate extension VideoManager: AVCaptureVideoDataOutputSampleBufferDelegate {       func captureOutput(_ output: AVCaptureOutput, didDrop sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {     delegate?.didReceive(sampleBuffer: sampleBuffer)   } } i tried like this AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) The camera uses only the front camera. how to use back camera?
Posted Last updated
.
Post marked as solved
1 Replies
954 Views
I am a student studying AR with ARkit. I want a variety of assets that can be used commercially. (there are limits to what I can do myself...) Is there any place where I can get assets(like 3Dmodels, usdz file etc.) like Unity's asset store? The resources on the Apple developer homepage are good but few, and don't know if they are commercially available.
Posted Last updated
.
Post marked as solved
2 Replies
796 Views
var name: String? = "name" if let copyname = name { print(copyname) } In this code, are name and copyname allocated in two different memory?
Posted Last updated
.
Post marked as solved
1 Replies
758 Views
I wonder how the + function is used directly. extension CGPoint {     static func add(lhs: Self, rhs: Self) -> CGPoint {         CGPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y)     }     static func +(lhs: Self, rhs: Self) -> CGPoint {         CGPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y)     } } private func testCGPoint() {     let dummy1 = CGPoint(x: 2, y: 3)     let dummy2 = CGPoint(x: 4, y: 5)     let dummy3: CGPoint = .add(lhs: dummy1, rhs: dummy2)     let dummy4: CGPoint = dummy1 + dummy2 } in my expectation, I thought that the + function would be used like the add function. i thought this form. CGPoint.+(lhs: dummy1, rhs: dummy2) But the + function did not. How are you doing this?
Posted Last updated
.