Post

Replies

Boosts

Views

Activity

Reply to Pass on the part which doesn't fit into the UILabel
Yes I use a Textfield. So my current approach looks like this but this doesn't work properly. When the button got pressed it calculates the part of the string which wasn't visible on the screen. That works fine but the string I get from the function is always a little bit longer than the acutal text I can see on my device. What am I doing wrong?@IBAction func buttonHandler(_ sender: UIButton) { let substring = stringThatFitsOnScreen(originalString: textView.text) let textOfTextView = viewText passToNextView = String(textOfTextView.dropFirst(substring!.count)) print(substring) print(passToNextView) performSegue(withIdentifier: "nextView", sender: self) } func stringThatFitsOnScreen(originalString: String) -> String? { // the visible rect area the text will fit into let userWidth = textView.bounds.size.width - textView.textContainerInset.right - textView.textContainerInset.left let userHeight = textView.bounds.size.height - textView.textContainerInset.top - textView.textContainerInset.bottom let rect = CGRect(x: 0, y: 0, width: userWidth, height: userHeight) // we need a new UITextView object to calculate the glyphRange. This is in addition to // the UITextView that actually shows the text (probably a IBOutlet) let tempTextView = UITextView(frame: self.textView.bounds) tempTextView.font = textView.font tempTextView.text = textView.text // get the layout manager and use it to layout the text let layoutManager = tempTextView.layoutManager layoutManager.ensureLayout(for: tempTextView.textContainer) // get the range of text that fits in visible rect let rangeThatFits = layoutManager.glyphRange(forBoundingRect: rect, in: tempTextView.textContainer) // convert from NSRange to Range guard let stringRange = Range(rangeThatFits, in: originalString) else { return nil } // return the text that fits let subString = originalString[stringRange] return String(subString) }
Dec ’19
Reply to Pass on the part which doesn't fit into the UILabel
So my current approach looks like this but this doesn't work properly. When the button got pressed it calculates the part of the string which wasn't visible on the screen. That works fine but the string I get from the function is always a little bit longer than the acutal text I can see on my device. What am I doing wrong? @IBAction func buttonHandler(_ sender: UIButton) { let substring = stringThatFitsOnScreen(originalString: textView.text) let textOfTextView = labelText passToNextView = String(textOfTextView.dropFirst(substring!.count)) print(substring) print(passToNextView) print(textView.intrinsicContentSize.width) performSegue(withIdentifier: "test", sender: self) } func stringThatFitsOnScreen(originalString: String) -> String? { // the visible rect area the text will fit into let userHeight = textView.bounds.size.height - textView.textContainerInset.top - textView.textContainerInset.bottom let userWidth = textView.bounds.size.width - textView.textContainerInset.right - textView.textContainerInset.left print(userWidth) let userHeight = textView.bounds.size.height - textView.textContainerInset.top - textView.textContainerInset.bottom //let userWidth = textView.intrinsicContentSize.width //let userHeight = textView.intrinsicContentSize.height let rect = CGRect(x: 0, y: 0, width: userWidth, height: userHeight) // we need a new UITextView object to calculate the glyphRange. This is in addition to // the UITextView that actually shows the text (probably a IBOutlet) let tempTextView = UITextView(frame: self.textView.bounds) tempTextView.font = textView.font tempTextView.text = textView.text // get the layout manager and use it to layout the text let layoutManager = tempTextView.layoutManager layoutManager.ensureLayout(for: tempTextView.textContainer) // get the range of text that fits in visible rect let rangeThatFits = layoutManager.glyphRange(forBoundingRect: rect, in: tempTextView.textContainer) // convert from NSRange to Range guard let stringRange = Range(rangeThatFits, in: originalString) else { return nil } // return the text that fits let subString = originalString[stringRange] return String(subString) }
Dec ’19
Reply to Read from smb server connected in 'Files' App
I was already trying bookmark: https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directoriesI found this in the Documentation. If you scroll down to Save the URL as a Bookmark could you please explain me where they get this from?getMyURLForBookmark()try bookmarkData.write(to: getMyURLForBookmark())How can I save the bookmark to use it later to write into the file.When I try bookmark I always get the errorCannot convert value of type 'appName.Data' to expected argument type 'Foundation.Data'And I also triedlet didStartAccessing = url.startAccessingSecurityScopedResource() defer { if didStartAccessing { url.stopAccessingSecurityScopedResource() } }But this doesn't help. I always get the error 'Operation not permitted'
Apr ’20
Reply to Read from smb server connected in 'Files' App
When I printed it in the console with the didPickDocumentAt function I copied it and pasted it in my read function. I know that this is very bad, but I couldn't figure out how to save it with bookmark.So my question now is how do I save the url in a bookmark when it calls didPickDocumentAt and than later use it in my writing/reading functions and do not get the error that I do not have the permission for this?
Apr ’20
Reply to Security scoped Bookmarks iOS - Swift
I am doing something wrong or it is not working.And I just realized that they: https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directoriescall when reading the Bookmarklet bookmarkData = try Data(contentsOf: getMyURLForBookmark())But this doesn't exists. I always get the errorArgument passed to call that takes no argumentsOnly NSData hasNSData(contentsOf: URL)If I want to use this and than transform it back to Data() I get the errorCannot convert value of type 'appName.Data' to expected argument type 'Foundation.Data'I just want to access a smb server in the files app or doesn't matter how. This can't be that difficult. Mhhh 😟
Apr ’20
Reply to Ad hoc App Distribution no Wifi connection?
Hello @robnotyou and @ChuckMN. Thx for both answering so fast :) Yes the problem is with my checking of the internet connection This is my code: public class InternetReachability {     class func isConnectedToNetwork() -> Bool {         var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))         zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))         zeroAddress.sin_family = sa_family_t(AF_INET)         let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) {             $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in                 SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress)             }         }         var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0)         if SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) == false {             return false         }         let isReachable = flags == .reachable         let needsConnection = flags == .connectionRequired         return isReachable && !needsConnection     } } The code above only works if I plug my phone in my computer and directly compline onto my phone, but not through ad hoc If I change the code to this both distributions work perfectly, but why does the above one doesn't work for ad hoc public class InternetReachability {     class func isConnectedToNetwork() -> Bool {         var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))         zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))         zeroAddress.sin_family = sa_family_t(AF_INET)         let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) {             $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in                 SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress)             }         }         var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0)         if SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) == false {             return false         }         let isReachable = (flags.rawValue & UInt32(kSCNetworkFlagsReachable)) != 0         let needsConnection = (flags.rawValue & UInt32(kSCNetworkFlagsConnectionRequired)) != 0         let ret = (isReachable && !needsConnection)         return ret     } }
Oct ’21