unsafemutablepointer

outputting a value to a typedef pointer in swift

随声附和 提交于 2019-12-11 17:34:53
问题 I'm almost certain the title of this isn't correct but here goes... I'm bridging to an Objective-C class to set a typedef. The bridge is set up and I'm able to declare the typedef var correctly. In Objective-C I also called a method from the same class that, when called, output a value to the variable TestHandle. var TestHandle : TESTHANDLE TestInit(&TestHandle) When I try this using Swift 5 I get this error: Cannot convert value of type 'inout TESTHANDLE' (aka 'inout UnsafeMutableRawPointer'

How to convert array to UnsafeMutablePointer<UnsafeRawPointer?> Swift 3.0?

女生的网名这么多〃 提交于 2019-12-08 21:58:20
问题 Here was my workable code in the previous version of Swift: let imageOptionsDictKeys = [ kCVPixelBufferPixelFormatTypeKey, kCVPixelBufferWidthKey, kCVPixelBufferHeightKey, kCVPixelBufferOpenGLESCompatibilityKey, kCVPixelBufferIOSurfacePropertiesKey] let imageOptionsDictValues = [ cvPixelFormatType, frameW, frameH, boolYES] var keyCallbacks = kCFTypeDictionaryKeyCallBacks var valueCallbacks = kCFTypeDictionaryValueCallBacks let imageOptions = CFDictionaryCreate(kCFAllocatorDefault,

Preparing for Swift 4 - UnsafeMutablePointer migration to UnsafeMutableBufferPointer

…衆ロ難τιáo~ 提交于 2019-12-08 11:03:02
问题 I've got a char-by-char function that returns a character from a file. It is pretty performant, as far as i now. Xcode says that the characterPointer.initialize(from: s.characters) "will be removed in Swift 4.0." And I have to "use 'UnsafeMutableBufferPointer.initialize(from:)' instead". But I can't get it. Can you please explain it to me. How to use a quick iterator over characters with a UnsafeMutableBufferPointer? Do you have an example? This is my function: /// Return next character, or

How do you satisfy the 'lineOrigins' argument in CTFrameGetLineOrigins() in Swift? [duplicate]

别等时光非礼了梦想. 提交于 2019-12-06 15:56:54
This question already has an answer here : Issue with CoreText CTFrameGetLineOrigins in Swift (1 answer) Closed last year . I'm trying to figure out CTFrameGetLineOrigins from here: CTFrameGetLineOrigins Got Incorrect Origins , and trying to convert the ObjC to Swift. Obj-C: CFArrayRef lines = CTFrameGetLines(frame); size_t numOfLines = CFArrayGetCount(lines); CGPoint lineOrigins[numOfLines]; CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), lineOrigins); Swift: let lines = CTFrameGetLines(frame) let numOfLines: size_t = CFArrayGetCount(lines) let lineOrigins = [CGPoint](repeating: CGPoint.zero,

Swift UnsafeMutablePointer: Must I call deinitialize before deallocate?

烂漫一生 提交于 2019-12-02 04:59:47
问题 Given an instance of UnsafeMutablePointer , what's the point of calling deinitialize(count:) right before deallocate(capacity:) ? Can't you just call deallocate(capacity:) ? I saw this when reading the section "Using Typed Pointers" of the article Unsafe Swift: Using Pointers And Interacting With C on raywenderlich.com. The article contains the code below, which you can add to a new playground in Xcode. let count = 2 let stride = MemoryLayout<Int>.stride let alignment = MemoryLayout<Int>

Swift UnsafeMutablePointer: Must I call deinitialize before deallocate?

江枫思渺然 提交于 2019-12-02 01:24:36
Given an instance of UnsafeMutablePointer , what's the point of calling deinitialize(count:) right before deallocate(capacity:) ? Can't you just call deallocate(capacity:) ? I saw this when reading the section "Using Typed Pointers" of the article Unsafe Swift: Using Pointers And Interacting With C on raywenderlich.com . The article contains the code below, which you can add to a new playground in Xcode. let count = 2 let stride = MemoryLayout<Int>.stride let alignment = MemoryLayout<Int>.alignment let byteCount = stride * count do { print("Typed pointers") let pointer = UnsafeMutablePointer

UnsafeMutablePointer<CFTypeRef> in Swift 3

淺唱寂寞╮ 提交于 2019-12-01 19:01:53
问题 I'm attempting to call SecItemCopyMatching in my keychain utility class in order to get data out of the keychain, yet I'm running into a problem with getting the result argument, UnsafeMutablePointer<CFTypeRef?> . The original statement (in Swift 2, before migrating to Swift 3) was // query is a dictionary of [String : AnyObject] var result: Data? let status = withUnsafeMutablePointer(to: &result) { SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0)) } But in Swift 3, you are

UnsafeMutablePointer<CFTypeRef> in Swift 3

与世无争的帅哥 提交于 2019-12-01 18:29:22
I'm attempting to call SecItemCopyMatching in my keychain utility class in order to get data out of the keychain, yet I'm running into a problem with getting the result argument, UnsafeMutablePointer<CFTypeRef?> . The original statement (in Swift 2, before migrating to Swift 3) was // query is a dictionary of [String : AnyObject] var result: Data? let status = withUnsafeMutablePointer(to: &result) { SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0)) } But in Swift 3, you are now required to call .withMemoryRebound in order to view memory. Based on what Xcode tells you to do,

Where to put views creation in MVVM and MVC patterns?

半城伤御伤魂 提交于 2019-12-01 12:30:26
Please excuse me if its repeated topic. I usually write my apps without storyboards, and put views creation into "viewDidLoad", like: class LoginVC: UIViewController { var view1: UIView! var label1: UILabel! override func viewDidLoad() { super.viewDidLoad() loadStaticViews() } func loadStaticViews() { view1 = UIView() label1 = UILabel() view.addSubview(view1) view1.addSubview(label1) // constraints... } } And now I want to try MVVM pattern in my next app, and just not sure where to put views creation. Now I think about something like that: class LoginVCViews { static func loadViews<T, T1, T2>

Where to put views creation in MVVM and MVC patterns?

北慕城南 提交于 2019-12-01 10:06:44
问题 Please excuse me if its repeated topic. I usually write my apps without storyboards, and put views creation into "viewDidLoad", like: class LoginVC: UIViewController { var view1: UIView! var label1: UILabel! override func viewDidLoad() { super.viewDidLoad() loadStaticViews() } func loadStaticViews() { view1 = UIView() label1 = UILabel() view.addSubview(view1) view1.addSubview(label1) // constraints... } } And now I want to try MVVM pattern in my next app, and just not sure where to put views