我目前正在使用Swift 2编写OS X应用程序.我想在没有XIB或Storyboard的情况下构建UI.我遇到的问题是初始化我可以将我的视图放入的自定义ViewController.
这是我的AppDelegate:
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
var viewController: MyViewController?
func applicationDidFinishLaunching(aNotification: NSNotification) {
viewController = MyViewController()
self.window.contentView!.addSubview(viewController!.view)
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
}
Run Code Online (Sandbox Code Playgroud)
和MyViewController:
class MyViewController: NSViewController {
var textField: NSTextField?
override func viewDidLoad() {
super.viewDidLoad()
textField = NSTextField(frame: NSRect(x: 10, y: 10, width: 100, height: 100))
textField!.bezeled = false
textField!.drawsBackground = false
textField!.editable = false
textField!.selectable = false
textField!.stringValue = …Run Code Online (Sandbox Code Playgroud) 我有一个接受多部分表单数据类型的方法。此方法的参数之一是file表单数据参数,如下所示
@FormDataParam("file") InputStream inputStream,
@FormDataParam("file") FormDataContentDisposition contentDispositionHeader
Run Code Online (Sandbox Code Playgroud)
我希望有时能够在不提供表单数据参数的情况下到达此端点file,但现在当我忽略它时,该方法会立即返回 400 bad request。有什么方法可以设置它以便我可以将其省略吗?或者有什么方法可以为此设置默认值(即为空?)。任何帮助,将不胜感激。我的方法声明如下:
@POST
@Path("/publish")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response publish(@Auth Key key,
@QueryParam("email") String email,
@HeaderParam("password") String password,
@QueryParam("type") PublishType type,
@QueryParam("message") String message,
@FormDataParam("file") InputStream inputStream,
@FormDataParam("file") FormDataContentDisposition
contentDispositionHeader,
@FormDataParam("title") @DefaultValue("") String videoTitle) {
// code here
}
Run Code Online (Sandbox Code Playgroud)
最后,我想创建一个端点,用户可以在其中将文本发布到数据库,并且可以选择包含图像或某种类型的媒体。让我知道是否有其他方法可以实现这一目标。
谢谢你!
我正在尝试将一个int添加到char数组中.我的(破损)代码如下,
string[i] = (char) number;
Run Code Online (Sandbox Code Playgroud)
与i数组的某个int索引并且number是一些整数.实际上,在输入时我注意到如果数字超过一位数就会出现另一个问题,所以如果你对这个问题有一些答案那就太棒了!
我正在尝试使用malloc分配一些内存(我没有太多使用malloc的经验,因为我刚开始学习如何使用它),并且在使用IDE编译之前我收到了警告.
int numInSeq = 0;
int i;
printf("How many numbers do you have in your sequence: ");
scanf("%d", &numInSeq);
double* sequence = (double*) malloc(numInSeq * sizeof(double));
printf("Enter the sequence of the numbers you have (seperated by spaces): ");
for (i = 0; i < numInSeq; i++) {
scanf("%lf", &sequence[i]);
}
Run Code Online (Sandbox Code Playgroud)
警告在我调用malloc的行上,它说:隐式声明类型为'void*(unsigned long)'的库函数'malloc'
这是不正确的格式化代码行的方式?该程序仍在编译,但在测试时我得到了一些意想不到的结果.