info

Home
[objective-c]NSURLDownload  @ App Develop , objective-c 2015年10月29日
NSURLDownload
- (void)startDownloadWithURL:(NSString*)urlstr
{
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlstr]
                                                cachePolicy:NSURLRequestUseProtocolCachePolicy
                                            timeoutInterval:5.0];
    NSURLDownload  *download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
    if (!download) {

    }
}
- (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename
{
    NSString *destinationFilename = @"ローカルファイルパス";
    [download setDestination:destinationFilename allowOverwrite:YES];
}
- (void)download:(NSURLDownload *)download didReceiveResponse:(NSURLResponse *)response
{

}
- (void)download:(NSURLDownload *)download didReceiveDataOfLength:(NSUInteger)length
{

}
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
{

}
- (void)downloadDidFinish:(NSURLDownload *)download
{

}
[objective-c]NSViewのフェード  @ App Develop , objective-c 2015年10月27日
NSViewのフェード
view.wantsLayer = YES;
view.hidden = NO;
view.layer.opacity = 1.0;
CABasicAnimation * alphaAnimation  = [CABasicAnimation animationWithKeyPath:@"opacity"];
alphaAnimation.removedOnCompletion =  YES;
alphaAnimation.autoreverses = NO;
alphaAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
alphaAnimation.duration = fadeDuration_;
alphaAnimation.fromValue = [NSNumber numberWithFloat:0.0];
alphaAnimation.toValue = [NSNumber numberWithFloat:1.0];
alphaAnimation.byValue = [NSNumber numberWithFloat:1.0];
[view.layer addAnimation:alphaAnimation forKey:@"opacityAnimation"];
[MacApp]アイコンの設定  @ App Develop , Xcode 2015年10月26日
アイコンの設定
・「sample.iconset」というフォルダを作成する※sampleは任意
・「sample.iconset」に下記ファイルを追加する※カッコ内は画像サイズ

・icon_16x16.png (16x16)
・icon_16x16@2x.png (32x32)
・icon_32x32.png (32x32)
・icon_32x32@2x.png (64x64)
・icon_128x128.png (128x128)
・icon_128x128@2x.png (256x256)
・icon_256x256.png (256x256)
・icon_256x256@2x.png (512x512)
・icon_512x512.png (512x512)
・icon_512x512@2x.png (1024x1024)

・「Info.plist」に「Icon files」を追加
・「Icon files」の「Item 0」に「sample」と入力

[Swift]UITextFieldのクリアボタンの色を変える  @ App Develop , Swift 2015年8月3日
UITextFieldのクリアボタンの色を変える
extension UITextField {
    func setTintColorToClearButton(){
        let anyobj:AnyObject? = self.valueForKey("_clearButton")
        if let anyobj:AnyObject = anyobj {
            if anyobj.isMemberOfClass(UIButton) {
                let button:UIButton = anyobj as UIButton
                if let image:UIImage = button.imageForState(.Highlighted) {
                    let paintedImage:UIImage = image.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
                    button.setImage(paintedImage, forState: .Normal)
                    button.setImage(paintedImage, forState: .Highlighted)
                }
            }
        }
    }
}

self.textField.tintColor = UIColor.whiteColor()
self.textField.setTintColorToClearButton()

before
textfield1

after
textfield2
[Swift]メモリアドレス取得  @ App Develop , Swift 2015年8月2日
メモリアドレス取得
func getMemoryAddress(target:AnyObject) -> String {
    return "\(unsafeAddressOf(target))"
}
let m1:String = self.getMemoryAddress(self.view1)
let m2:String = self.getMemoryAddress(self.view2)
println("mem:\(m1)")
println("mem:\(m2)")
println("m1 < m2 = \(m1 < m2)")
println("m2 < m1 = \(m2 < m1)")

結果
mem:0x00007fe718c4da20
mem:0x00007fe718c42f20
m1 < m2 = false
m2 < m1 = true
[Swift]クラス判別  @ App Develop , Swift 2015年8月1日
クラス判別
let button:UIButton = UIButton()
let anyobj:AnyObject = button

if anyobj.isKindOfClass(UIView) {//対象クラスのサブクラスでもtrue
    println("anyobj is kind of UIView")
}
if anyobj.isMemberOfClass(UIView) {
    println("anyobj is member of UIView")
}
if anyobj.isMemberOfClass(UIButton) {
    println("anyobj is member of UIButton")
}
if anyobj is UIView {//対象クラスのサブクラスでもtrue
    println("anyobj is UIView")
}
if anyobj is UIButton {
    println("anyobj is UIButton")
}

結果
anyobj is kind of UIView
anyobj is member of UIButton
anyobj is UIView
anyobj is UIButton