Is there method indiicate current thread is mainthread in swift?


(qi bo) #1

isMainThread is an method in object-c. how to indicate current thread is main thread?

thank you
Bob


(Chéyo Jiménez) #2

//swift 2.2+
NSThread.isMainThread()

//swift 3+
Thread.isMainThread

···

On Jul 13, 2016, at 12:27 AM, qi bo via swift-users <swift-users@swift.org> wrote:

isMainThread is an method in object-c. how to indicate current thread is main thread?

thank you
Bob

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Nate Birkholz) #3

Is this a change to NSThread in the release, or to the language, dropping
empty () when calling methods? If the latter, what proposal is it? i can't
find it.

···

On Wed, Jul 13, 2016 at 12:41 AM, Jose Cheyo Jimenez via swift-users < swift-users@swift.org> wrote:

//swift 2.2+
NSThread.isMainThread()

//swift 3+
Thread.isMainThread

On Jul 13, 2016, at 12:27 AM, qi bo via swift-users <swift-users@swift.org> > wrote:

isMainThread is an method in object-c. how to indicate current thread is
main thread?

thank you
Bob
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
Nate Birkholz


(Chéyo Jiménez) #4

That's probably part of the new naming guidelines.

···

On Jul 13, 2016, at 7:13 AM, Nate Birkholz <nbirkholz@gmail.com> wrote:

Is this a change to NSThread in the release, or to the language, dropping empty () when calling methods? If the latter, what proposal is it? i can't find it.

On Wed, Jul 13, 2016 at 12:41 AM, Jose Cheyo Jimenez via swift-users <swift-users@swift.org> wrote:
//swift 2.2+
NSThread.isMainThread()

//swift 3+
Thread.isMainThread

On Jul 13, 2016, at 12:27 AM, qi bo via swift-users <swift-users@swift.org> wrote:

isMainThread is an method in object-c. how to indicate current thread is main thread?

thank you
Bob

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
Nate Birkholz


(qi bo) #5

my swift is 2016-05-09-a-ubuntu14.04.
import Foundation
if Thread.isMainThread {
...
}
but unresolved identifier "Thread" occur

···

On Wed, Jul 13, 2016 at 3:41 PM +0800, "Jose Cheyo Jimenez" <cheyo@masters3d.com<mailto:cheyo@masters3d.com>> wrote:

//swift 2.2+
NSThread.isMainThread()

//swift 3+
Thread.isMainThread

On Jul 13, 2016, at 12:27 AM, qi bo via swift-users <swift-users@swift.org<mailto:swift-users@swift.org>> wrote:

isMainThread is an method in object-c. how to indicate current thread is main thread?

thank you
Bob

_______________________________________________
swift-users mailing list
swift-users@swift.org<mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users


(Mark Dalrymple) #6

It's a change in Xcode 8.2 - NSThread.isMainThread in ObjC land is now a
class property:

@property (class, readonly) BOOL isMainThread NS_AVAILABLE(10_5, 2_0);

In Xcode 8.1(and since iPhone OS 2) it was a regular old-school class
method:

+ (BOOL)isMainThread NS_AVAILABLE(10_5, 2_0)

and so it loses the paren requirement now.

++md

···

On Wed, Jul 13, 2016 at 10:13 AM, Nate Birkholz via swift-users < swift-users@swift.org> wrote:

Is this a change to NSThread in the release, or to the language, dropping
empty () when calling methods? If the latter, what proposal is it? i can't
find it.

On Wed, Jul 13, 2016 at 12:41 AM, Jose Cheyo Jimenez via swift-users < > swift-users@swift.org> wrote:

//swift 2.2+
NSThread.isMainThread()

//swift 3+
Thread.isMainThread

On Jul 13, 2016, at 12:27 AM, qi bo via swift-users < >> swift-users@swift.org> wrote:

isMainThread is an method in object-c. how to indicate current thread is
main thread?

thank you
Bob
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
Nate Birkholz

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Chéyo Jiménez) #7

Oh, I think foundation on Linux is not up to date yet.

···

On Jul 13, 2016, at 1:12 AM, qi bo <qibo_cn@outlook.com> wrote:

my swift is 2016-05-09-a-ubuntu14.04.
import Foundation
if Thread.isMainThread {
...
}
but unresolved identifier "Thread" occur

On Wed, Jul 13, 2016 at 3:41 PM +0800, "Jose Cheyo Jimenez" <cheyo@masters3d.com> wrote:

//swift 2.2+
NSThread.isMainThread()

//swift 3+
Thread.isMainThread

On Jul 13, 2016, at 12:27 AM, qi bo via swift-users <swift-users@swift.org> wrote:

isMainThread is an method in object-c. how to indicate current thread is main thread?

thank you
Bob

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Jens Alfke) #8

It's a change in Xcode 8.2 - NSThread.isMainThread in ObjC land is now a class property:

    ^^ Xcode 8.0 (beta)

In Xcode 8.1(and since iPhone OS 2) it was a regular old-school class method:

  ^^ Xcode 7.x

Strictly speaking, this is a change in the iOS 10 / macOS 10.12 SDKs (but of course they’re rev-locked to Xcode versions.)

—Jens

···

On Jul 13, 2016, at 7:20 AM, Mark Dalrymple via swift-users <swift-users@swift.org> wrote:


(Mark Dalrymple) #9

To really split hairs, the iPhone 10.10 SDK from Xcode 8.0 beta 1 has the
+isMainThread, and beta 2 has the class property :slight_smile: (being a collector of
header files...)

(and I do need to break that 8.2 for 8-beta-2 habit)

++md

···

On Wed, Jul 13, 2016 at 11:34 AM, Jens Alfke <jens@mooseyard.com> wrote:

> On Jul 13, 2016, at 7:20 AM, Mark Dalrymple via swift-users < > swift-users@swift.org> wrote:
>
> It's a change in Xcode 8.2 - NSThread.isMainThread in ObjC land is now a
class property:

                ^^ Xcode 8.0 (beta)

> In Xcode 8.1(and since iPhone OS 2) it was a regular old-school class
method:

        ^^ Xcode 7.x

Strictly speaking, this is a change in the iOS 10 / macOS 10.12 SDKs (but
of course they’re rev-locked to Xcode versions.)

—Jens