Posts

Post not yet marked as solved
0 Replies
587 Views
Xcode supported inclusion of PDF files for quite a while now. first it was done by converting them into png images at build time, lately you would be able setting "Preserve Vector Data" in the asset catalogue's image so that would keep vector images "vector" all until rendering. but how that's actually done internally? i don't seem able to use UIImage(data: pdfFileData) to build images from pdfs. i can use UIGraphicsImageRenderer based code or another code that creates CGContext of a needed size and draws PDF into it, but i wonder how system does this? any code that i can think of requires creating bitmap context of a particular size (in pixels) and rendering into it, which loses the "vectorness" of the image (ability to scale nicely). so the question is, if my image assets are not available at build time (and i am not able including them into an asset catalogue, but have them as a Data instances at runtime) what is the way to mimic the system behaviour of creating vector-preserved UIImage's out of pdfs?
Posted Last updated
.
Post not yet marked as solved
0 Replies
318 Views
hello, what is the best way to handle this request:when user presses return/enter on a physical keyboard connected to iOS device the app shall do one thing (take the contents of UITextView and proceed with it), and when the user presses alt+return/enter on a physical keyboard the app shall do another thing (treat it as a usual text input and change UITextView contents accordingly). ideally when user pastes the "\n" symbol via copy / paste the app shall treat it as a normal text input following the second path, but that requirement can be sacrificed.i tried overriding pressesBegan in a UITextView subclass but don't see it being called.is there a way to take the current keyboard modifiers on iOS? (similar to the ancient GetKeys on mac for those who remember)
Posted Last updated
.
Post marked as solved
21 Replies
8.4k Views
FB6684220my app that worked fine under Xcode 10 crashes under Xcode 11 (beta 3). I distilled the crash down to this: when accessing dictionary concurrently some of the acceses crash. interestingly it happens only under iOS, not under macOS. FB6684220========import Foundationvar dict: [String : String] = [:]func test() { Thread.detachNewThread { var counter = 0 while true { counter += 1 let key = String.random dict[key] = .random usleep((0...1000).randomElement()!) } } Thread.detachNewThread { var counter = 0 while true { counter += 1 let key = String.random let value = dict[key] usleep((0...1000).randomElement()!) } }}extension String { static var random: String { let s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " let offset = (0 ... 100).randomElement()! let len = (1 ... 100).randomElement()! return String(s[s.index(s.startIndex, offsetBy: offset) ... s.index(s.startIndex, offsetBy: offset + len)]) }}
Posted Last updated
.
Post marked as solved
6 Replies
1.1k Views
a preambula,i created a helper function:func cast<T>(_ value: Any?, to: T.Type) -> T? { return value != nil ? (value as! T) : nil}to use it like this:let dog = cast(any, to: Dog.self)the idea is that it is a "stricter" version of the "as?" operator:let dog = any as? Dog // will return nil when a car is passed, i want a crash here in this case.let dog = any != nil ? (any as! Dog) // so i want this: if it is not nil it must be a dog (*)let dog = cast(any, to: Dog.self) // a bit shorter and less visually disturbing(* note that the extra parens around "(any as! Dog)" are there to stop a warning).now the question, probably to swift designers, but anyone's input is welcome:this cast function is not as nice as the built-in "as?" operator. i can not pass "Dog" alone in this context, I have to put it as "Dog.self". is there some deep logic why it is so? i believe in this context "Dog" alone can not mean anything else (useful), what harm it would make to treat "Dog" here as if "Dog.self" was passed?
Posted Last updated
.