1

本から入手したObjective-CコードをSwiftに翻訳しています。問題のコードは、NSTextContainerメソッドのカスタム実装です。

-(NSRect)lineFragmentRectForProposedRect:(NSRect)proposedRect
                          sweepDirection:(NSLineSweepDirection)sweepDirection
                       movementDirection:(NSLineMovementDirection)movementDirection
                           remainingRect:(NSRectPointer)remainingRect
{

 // ... now set value of the struct pointed at by NSRectPointer
 *remainingRect = NSRectMake(0, 0, 100, 50);

 //...
 return mainRect;
}

これを Swift で複製するのに苦労しています。何を試しても、let変数に代入できないと言われ続けています。

4

1 に答える 1

2

NSRectPointerと定義されている

public typealias NSRectPointer = UnsafeMutablePointer<NSRect>

そしてUnsafeMutablePointer持っています

/// Access the underlying raw memory, getting and setting values.
public var memory: Memory { get nonmutating set }

プロパティ、したがって、Objective-C コードの Swift 版

*remainingRect = NSRectMake(0, 0, 100, 50);

する必要があります

remainingRect.memory = NSMakeRect(0, 0, 100, 50)
于 2015-11-04T11:09:43.790 に答える