macOS/iOS API解説

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

目次

isFilePackageAtPath:

INDEX>AppKit>NSWorkspace

パッケージかを返します

Objective-C

- (BOOL)isFilePackageAtPath:(NSString *)fullPath

Swift

func isFilePackageAtPath(_ fullPath: String) -> Bool

解説

パッケージかを返します。

返り値

Objective-C

BOOL

Swift

Bool

ファイルパッケージかYES/NO

引数

Objective-C

(NSString *)fullPath

Swift

_ fullPath: String

フルパス

フレームワーク

ApplicationKit

クラス

NSWorkspace

使用可能

10.0

参照

更新時のバージョン

OS X 10.10.3
Swift1.2

例文

#import "SetImage.h"

@implementation SetImage

- (IBAction)set:(id)sender
{

 //開けるファイル拡張子の配列
    NSArray      *fileTypes    = [ NSArray arrayWithObject : @"app" ];
    //OpenPanelを作る
    NSOpenPanel  *opPanel       = [ NSOpenPanel openPanel ];

    //OpenPanelの結果のボタン番号
    int		  opRet;

     
        //OpenPanelでファイル選択   
    opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
                                     file : @"Pictures" //どのどのファイルを選択しておくか
                                    types : fileTypes ];//選べるファイルタイプ

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
    
        if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:[ opPanel filename ] ]){
        NSLog(@"YES");
        }
        else
        {
        NSLog(@"NO");
        }

    }

}

@end

Swift

    //NSWorkspace isFilePackageAtPath
    @IBAction func function026(sender: AnyObject) {
        //ファイルを選択
        var openPanel = NSOpenPanel()
        openPanel.allowsMultipleSelection = false
        openPanel.canChooseDirectories = false
        openPanel.canCreateDirectories = false
        openPanel.canChooseFiles = true
        openPanel.beginWithCompletionHandler { (result) -> Void in
            //オープンパネルでOKを選択したら
            if result == NSFileHandlingPanelOKButton {
                //選択したファイルを
                let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace()
                let theURL : NSURL =  openPanel.URL!
                let filepath : NSString = theURL.path!
                                // -> hfs,hfs
                if (theWorkspace.isFilePackageAtPath(filepath as String)) {
                    NSLog("filePackage?:YES")
                }else{
                    NSLog("filePackage?:NO")
                }
                
            }//if result
        }//openPanel.beginWithCompletionHandler
    }