Guten Tag liebe Community.
Ich release heute ein kleinen Downloader der in Swift geschrieben worden ist (von mir und einen Kollegen).
Hier mal ein kleiner Einblick:
Form
Code-Snippets:
AppDelegate.Swift
Code
//
// AppDelegate.swift
// Minecraft Skin Downloader
//
// Created by Necmi Hasan on 19.09.14.
// Copyright (c) 2014 Necmi Hasan. All rights reserved.
//
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate, NSOpenSavePanelDelegate{
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var textBox1: NSTextField!
@IBOutlet weak var imageview: NSImageView!
func applicationDidFinishLaunching(aNotification: NSNotification?) {
// Insert code here to initialize your application
}
func applicationWillTerminate(aNotification: NSNotification?) {
// Insert code here to tear down your application
}
@IBAction func AnzeigeButtonClick(sender: NSButton) {
if textBox1.stringValue.isEmpty {
var alert :NSAlert = NSAlert()
alert.addButtonWithTitle("Ok")
alert.messageText = "Das Textfeld ist leer!"
alert.informativeText = "Das Textfeld ist leer!"
alert.alertStyle = NSAlertStyle.WarningAlertStyle
alert.runModal()
} else {
var url = NSURL.URLWithString("http://s3.amazonaws.com/MinecraftSkins/" + textBox1.stringValue + ".png")
imageview.image = NSImage(contentsOfURL : url)
}
}
@IBAction func downloadButtonClick(sender: NSButton) {
let openDlg : NSSavePanel = NSSavePanel()
openDlg.canCreateDirectories = false
openDlg.nameFieldStringValue = textBox1.stringValue + ".png"
openDlg.delegate = self;
openDlg.runModal()
}
func panel(sender: AnyObject!, validateURL url: NSURL!, error outError: NSErrorPointer) -> Bool {
if(self.imageview.image != nil) {
var bitImageRep : NSBitmapImageRep = self.imageview.image.representations[0] as NSBitmapImageRep
var data : NSData = bitImageRep.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: nil)
data.writeToURL(url, atomically: true)
} else {
}
return true
}
}
Alles anzeigen
Download (Source): MEGA
Virustotal: Antivirus scan for 668271b332661fff9ba5609bddf40a1a73fdf747f8c948c4a46c816d81b4afd1 at
2014-09-26 17:18:23 UTC - VirusTotal
Systemvoraussetzung: Mac OS X 10.10 Yosemite (oder xCode 6 Beta)
MfG.