[swift-users] Exclamation mark's in swift parameter listings?

Rien Rien at Balancingrock.nl
Tue Jan 10 01:19:52 CST 2017


It means that a call to that function with an optional will unwrap the optional before it is used.

That is quite neat when dealing with C-API’s because often you will receive a pointer from a C-function which is optional to account for the fact that it can be NULL (= nil).
By using a forced unwrapped input parameter you are saved the trouble of unwrapping all these pointers when using them as input for other C-APIs.

In short, it makes it easier to interface with C-API’s.

Note that there is some under-the-hood magic going on because a C-pointer is an unboxed value, while a ‘normal’ optional is a boxed value.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Swiftrien
Project: http://swiftfire.nl




> On 10 Jan 2017, at 01:23, Ethin Probst via swift-users <swift-users at swift.org> wrote:
> 
> Hello all,
> I was wondering what an exclamation mark in a swift parameter listing
> means. For instance, I used Elements Oxidizer Live to translate some
> C# code into Swift. Reviewing it, I found the following (among
> others):
> @DllImport("ScriptHookV.dll")
> private static __extern func scriptRegister(_ module: System.IntPtr!,
> _ LP_SCRIPT_MAIN: LP_SCRIPT_MAINDelegate!)
> What I'm wondering is what does the '!' in that list of parameters
> mean? I also saw it when writing another program:
>    func MainForm_Load(_ sender: System.Object!, _ e: System.EventArgs!) {
> // ...
> }
> I don't recall the swift book teaching you what that means, so could
> someone tell me what those mean?
> -- 
> Signed,
> Ethin D. Probst
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list