macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

NSWorkspaceDidRenameVolumeNotification User Info Keys

INDEX>AppKit>NSWorkspace

リネーム時の追加情報

Objective-C

NSString * const NSWorkspaceVolumeOldLocalizedNameKey;
NSString * const NSWorkspaceVolumeOldURLKey;

Swift

let NSWorkspaceVolumeOldLocalizedNameKey: String
let NSWorkspaceVolumeOldURLKey: String

解説

フレームワーク

ApplicationKit

クラス

NSWorkspace

使用可能

10.6-

更新時のバージョン

OS X 10.10.3
Swift1.2

参照

関連記事(外部サイト)

例文

Objective-C

Swift

    //NSWorkspace NSWorkspaceDidRenameVolumeNotification
    //NSWorkspace NSWorkspaceDidMountNotification
    //NSWorkspace NSWorkspaceWillUnmountNotification
    //NSWorkspace NSWorkspaceDidUnmountNotification
    //NSWorkspace Volume Mounting Notification User Info Keys
    
    var switch053 : Bool = false
    func notify053(notify:NSNotification) {
        //NSLog("!! %@",notify.description)
        
        //マウントされたとき
        if notify.name == NSWorkspaceDidMountNotification {
            //NSLog("!! %@",notify.description)
            let devicePath : String = (notify.userInfo! as Dictionary)["NSDevicePath"]! as! String
            NSLog("device path = %@",devicePath)
            // =>device path = /Volumes/ディスクイメージ
            let localizedName : String = (notify.userInfo! as Dictionary)["NSWorkspaceVolumeLocalizedNameKey"]! as! String
            NSLog("localized new name = %@",localizedName)
            // =>localized new name = ディスクイメージ
            let newURL : NSURL = (notify.userInfo! as Dictionary)["NSWorkspaceVolumeURLKey"]! as! NSURL
            NSLog("new URL = %@",newURL.path!)
            // =>new URL = /Volumes/ディスクイメージ

        }
        //アンマウントしようとした時
        if notify.name == NSWorkspaceWillUnmountNotification {
            let devicePath : String = (notify.userInfo! as Dictionary)["NSDevicePath"]! as! String
            NSLog("device path = %@",devicePath)
            // =>device path = /Volumes/ディスクイメージ
            let localizedName : String = (notify.userInfo! as Dictionary)["NSWorkspaceVolumeLocalizedNameKey"]! as! String
            NSLog("localized new name = %@",localizedName)
            // =>localized new name = ディスクイメージ
            let newURL : NSURL = (notify.userInfo! as Dictionary)["NSWorkspaceVolumeURLKey"]! as! NSURL
            NSLog("new URL = %@",newURL.path!)
            // =>new URL = /Volumes/ディスクイメージ
        }
        if notify.name == NSWorkspaceDidUnmountNotification {
            NSLog("!! %@",notify.description)
            let devicePath : String = (notify.userInfo! as Dictionary)["NSDevicePath"]! as! String
            NSLog("device path = %@",devicePath)
            // =>device path = /Volumes/ディスクイメージ
            let localizedName : String = (notify.userInfo! as Dictionary)["NSWorkspaceVolumeLocalizedNameKey"]! as! String
            NSLog("localized new name = %@",localizedName)
            // =>localized new name = ディスクイメージ
            let newURL : NSURL = (notify.userInfo! as Dictionary)["NSWorkspaceVolumeURLKey"]! as! NSURL
            NSLog("new URL = %@",newURL.path!)
            // =>new URL = /Volumes/ディスクイメージ
        }
        if notify.name == NSWorkspaceDidRenameVolumeNotification {
            NSLog("NSWorkspaceDidRenameVolumeNotification")
            
            let localizedName : String = (notify.userInfo! as Dictionary)["NSWorkspaceVolumeLocalizedNameKey"]! as! String
            NSLog("localized new name = %@",localizedName)
            // =>localized new name = ディスクイメージ2
            let localizedOldName : String = (notify.userInfo! as Dictionary)["NSWorkspaceVolumeOldLocalizedNameKey"]! as! String
            NSLog("localized old name = %@",localizedOldName)
            // =>localized old name = ディスクイメージ1
            
            let newURL : NSURL = (notify.userInfo! as Dictionary)["NSWorkspaceVolumeURLKey"]! as! NSURL
            NSLog("new URL = %@",newURL.path!)
            // =>new URL = /Volumes/ディスクイメージ2
            let oldURL : NSURL = (notify.userInfo! as Dictionary)["NSWorkspaceVolumeOldURLKey"]! as! NSURL
            NSLog("old URL = %@",oldURL.path!)
            // =>old URL = /Volumes/ディスクイメージ1
        }

        
    }
    @IBAction func function053(sender: AnyObject) {
        let notificationName1 : String = NSWorkspaceDidRenameVolumeNotification
        let notificationName2 : String = NSWorkspaceDidMountNotification
        let notificationName3 : String = NSWorkspaceWillUnmountNotification
        let notificationName4 : String = NSWorkspaceDidUnmountNotification
        let notificationSelector : Selector = Selector("notify053:")
        
        if switch053 {
            //通知の監視をやめる
            NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self,
                name: notificationName1, object: nil )
            NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self,
                name: notificationName2, object: nil )
            NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self,
                name: notificationName3, object: nil )
            NSWorkspace.sharedWorkspace().notificationCenter.removeObserver(self,
                name: notificationName4, object: nil )
            NSLog("--------observe off")
            switch053 = false
            
        }else{
            //通知の監視を始める
            NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self,
                selector: notificationSelector, name: notificationName1, object: nil )
            NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self,
                selector: notificationSelector, name: notificationName2, object: nil )
            NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self,
                selector: notificationSelector, name: notificationName3, object: nil )
            NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self,
                selector: notificationSelector, name: notificationName4, object: nil )
            NSLog("--------observe on")
            switch053 = true
        }
    }