Mount Network Share

  1. 3 years ago
    Edited 3 years ago by philcebutv


    How do I code on mounting different network share e.g. (AFP).

    Can anyone share. I am stuck on this..

    my xcode is almost complete except that I do not know how to code to mount the shared folder. I have already all the window and coded all the fields but coding the actual mounting is a bit hard. I did not find any sample on the net.

    on applescript this will only be a one liner syntax, given that username, password and server fields are there - mount volume "afp://" & user_name & ":" & pass_word & "@" & server_name


  2. anyone?

  3. niutech

    24 Mar 2016 Administrator
    Edited 3 years ago by niutech

    You can do it like this in Swift, using NetFS:

    func mountShare(serverAddress: String, shareName: String, userName: String, password: String) {
        let fm = NSFileManager.defaultManager()
        let mountPoint = "/Volumes/".stringByAppendingString(shareName)
        var isDir : ObjCBool = false
        if fm.fileExistsAtPath(mountPoint, isDirectory: &isDir) {
            if isDir {
                unmount(mountPoint, 0)
                println("Unmounted: \(mountPoint)")
        let sharePath = NSURL(string: "\(serverAddress)/\(shareName)")!
        let mounted : Int32 = NetFSMountURLSync(sharePath, nil, userName, self.decodeStr(password), nil, nil, nil)
        if mounted > 0 {
            println("Error: sharePath: \(sharePath) Not Valid")
        } else {
            println("Mounted: \(sharePath)")

or Sign Up to reply!