(Xcode 10.1, Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1))I'm developing an App (my first one) and during the development process I'd rather have a debug window into which I can write messages for development and debugging purposes.I have a UItextView for this and to get all print() into that textView, I'm using the following construct (pipe()) inspired by this://
// ViewController.swift
// Scroll View Demo
//
// Created by chriskuku on 30.12.18.
// Copyright © 2018 chriskuku. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var writeButton: UIButton!
var pipe = Pipe()
var count = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// dup2() makes newfd (new file descriptor) be the copy of oldfd (old file descriptor), closing newfd first if necessary.
dup2(pipe.fileHandleForWriting.fileDescriptor, STDOUT_FILENO)
// listening on the readabilityHandler
pipe.fileHandleForReading.readabilityHandler = { [weak self] handle in
let data = handle.availableData
let str = String(data: data, encoding: .ascii) ?? "\n"
DispatchQueue.main.async {
self?.textView.text += str
}
}
print("\npipe started")
}
@IBAction func buttonPressed(_ sender: Any) {
print("\(count). Hello world")
count += 1
}
}The App works fine when being run within Xcode on either virtual device (iPhone 6s plus in my case) or physially on the device connected to Xcode.But when I run the app alone on the target device (Apple iPhone 6splus), the pipe() mechanism doesn't seem to work. Nothing appears but the Initial text.I'm puzzled.
Selecting any option will automatically load the page