Skip to content

Conversation

@parkera
Copy link
Contributor

@parkera parkera commented Jul 21, 2016

What's in this pull request?

When we worked on the first version of naming fixes to the automatic import into Swift, we chose to make -[NSCoder encodeInt:forKey:] unavailable, to avoid a conflict with -[NSCoder encodeInt32:forKey:], as they would end up with the same name in Swift.

However, if you wish to subclass NSCoder in Swift, then you have to override this method. If it is unavailable, then you cannot do so, and if anyone that is encoded using this coder calls it, NSCoder will throw an exception. These methods are abstract in that class:

- (void)encodeInt:(int)intv forKey:(NSString *)key;
- (void)encodeInt32:(int32_t)intv forKey:(NSString *)key;
- (void)encodeInt64:(int64_t)intv forKey:(NSString *)key;

Therefore, we are bringing the method back, but with a slightly different name to resolve the ambiguity.

Import the C integer primitive encode and decode methods as:

extension NSCoder {
    func encodeCInt(_ value: Int32, forKey key: String) // ObjC: -encodeInt:forKey:
    func decodeCInt(forKey key: String) -> Int32 // ObjC: -decodeIntForKey:
}

This will join the existing family of methods:

extension NSCoder {
    func encode(_ value: Int32, forKey key: String) // ObjC: -encodeInt32:forKey:
    func encode(_ value: Int64, forKey key: String) // ObjC: -encodeInt64:forKey:
    func encode(_ value: Int, forKey key: String) // ObjC: -encodeInteger:forKey:

    func decodeInt32(forKey key: String) -> Int32 // ObjC: -decodeInt32ForKey:
    func decodeInt64(forKey key: String) -> Int64 // ObjC: -decodeInt32ForKey:
    func decodeInteger(forKey key: String) -> Int // ObjC: -decodeIntegerForKey:
}

We did not choose to rename Integer to Int in our APIs for coding.

We will continue to make these two functions unavailable on NSKeyedArchiver and NSKeyedUnarchiver, to avoid confusion with the other encode/decode methods that use integers.

Resolved bug number:

rdar://problem/27425997


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

A smoke test on macOS does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library only for macOS. Simulator standard libraries and
    device standard libraries are not built.
  3. lldb is not built.
  4. The test and validation-test targets are run only for macOS. The optimized
    version of these tests are not run.

A smoke test on Linux does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library incrementally.
  3. lldb is built incrementally.
  4. The swift test and validation-test targets are run. The optimized version of these
    tests are not run.
  5. lldb is tested.

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@parkera parkera self-assigned this Jul 21, 2016
@parkera
Copy link
Contributor Author

parkera commented Jul 21, 2016

@swift-ci Please test and merge

@swift-ci swift-ci merged commit 1142318 into swiftlang:master Jul 21, 2016
@johnspurlock
Copy link

Thanks Tony

@parkera
Copy link
Contributor Author

parkera commented Jul 22, 2016

Thank you for finding this and letting me know!

@parkera parkera deleted the nscoder_encodeint branch July 24, 2016 21:14
@johnspurlock
Copy link

Did this fix land in the swift version as of xcode beta 4?

Apple Swift version 3.0 (swiftlang-800.0.41.2 clang-800.0.36)

@parkera
Copy link
Contributor Author

parkera commented Aug 2, 2016

No, Xcode beta 4 used about the same version of the overlay as beta 3 did, due to the numerous pending changes in swift's master branch between the two. This change will be in the next beta, or you can try it out with the daily snapshots (that would be a great way to verify).

@johnspurlock
Copy link

Ok I'll wait for the next beta then, thanks

@johnspurlock
Copy link

Doesn't look like the fix is in xcode beta 5. Tony, can you confirm?

Apple Swift version 3.0 (swiftlang-800.0.42.1 clang-800.0.36.1)

@parkera
Copy link
Contributor Author

parkera commented Aug 9, 2016

I'm not sure at this point; the change is clearly in the swift-3.0-branch so I'm not sure why it's not making it into the seeds. Can you double check with a swift 3 snapshot?

@jckarter
Copy link
Contributor

jckarter commented Aug 9, 2016

Beta 5 has the same compiler and overlays as 4, for the most part. You should be able to try a snapshot toolchain from swift.org, though.

@johnspurlock
Copy link

Ah ok - that would explain why the beta 4 -> beta 5 migration did not require any corresponding changes on my side this time. Thanks, I suspected I had a bad installation at first.

@johnspurlock
Copy link

Verified fixed in beta 6 with the new encodeCInt methods, thanks.

Apple Swift version 3.0 (swiftlang-800.0.43.6 clang-800.0.38)

kateinoigakukun pushed a commit that referenced this pull request Aug 31, 2022
[pull] swiftwasm from main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants