0
import Foundation
import SystemConfiguration

for interface in SCNetworkInterfaceCopyAll() as NSArray {
    if let name = SCNetworkInterfaceGetBSDName(interface as! SCNetworkInterface),
       let type = SCNetworkInterfaceGetInterfaceType(interface as! SCNetworkInterface) {
            print("Interface \(name) is of type \(type)")
    }
}

can any one help me. I want to use SCNetworkInterface methods in my code. But i found this swift code. I am unable to understand this.especially syntax as!

1
  • 1
    What's the question? Commented Jul 24, 2016 at 15:19

2 Answers 2

1

Don't worry about the as!. It is a forced cast from an optional to a specific type. In Objective-C you just have a pointer; type conversions are handled more loosely.

Thus,

NSString *name = SCNetworkInterfaceGetBSDName(interface);

should suffice.

Sign up to request clarification or add additional context in comments.

6 Comments

What could be the interface. when i give en0, it is giving error
You should take the result of SCNetworkInterfaceCopyAll(), not provide your own. You can examine the result of that call to find out what the interface you need should be.
I am new to SCNetworkinterface class , and spending more than a week on this, could you please help me to get over this. I too will learn with you. Could you please translate my snippet to objective -c
@syammala Do you know any Objective C?
@AMomchilov Yes i do
|
0

The code you posted is from this SO post. And this SO post answers your question.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.