pixelglow / ZipZap

zip file I/O library for iOS, macOS and tvOS
BSD 2-Clause "Simplified" License
1.22k stars 199 forks source link

Comparison of ZZarchiveEntry.fileMode and S_IFDIF not working on Swift #136

Closed otaviokz closed 8 years ago

otaviokz commented 8 years ago

Initial problem

"if (entry.fileMode & S_IFDIR)" isn't accepted by the Swift compiler, get "Ambiguous reference to member &".

Tried to use "if entry.fileMode == S_IFDIR".

It's accepted by the compiler but, in Swift, "fileMode" returns "16877" when it's a directory. Printing S_IFDIR in debug console returns "16877".

pixelglow commented 8 years ago

Try this instead: if (entry.fileMode & S_IFDIR) != 0

In Swift, integers like fileMode don't automatically convert to booleans for the if statement. Hence you need the additional != 0 to convert it to boolean.