Michael Bryan

Michael Bryan

1557157962

Method Internals in Swift 5.0

In this post, we continue to get a better understanding of the internal workings of Swift by examining how methods work in this language.

One of the nice things about Swift 5 is the final stabilization of the ABI. This is actually a big deal. The application binary interface defines exactly how data is stored in programs, shared from libraries, things like that. It includes name decoration, class and object definitions, and so on. Now that we have a stable ABI, building tools that analyzed and manipulate these binary representations will become much, well, not easier, but not as much a waste of time. Until now, you were just about guaranteed to have any tools you created broken by new Swift versions. With a stable ABI? This shouldn't happen.

We just covered how classes are defined in Swift 5, and we discovered that they reflect the basic design in Objective-C. There are some key differences though, and one of those is member method definitions.

In Objective-C, you might remember that methods defined in a data pointer are stored in the class definition. This data pointer contained another pointer than references a list of method structures. The method structures contained a name, a pointer to an implementation, and a few other things. Let's see what Swift does.

First, we know swift does use the objc_class structure, and in this case it looks like this:

_$s9swift_cmd7PrinterCN:
  struct __objc_class {
  _$s9swift_cmd7PrinterCMm, // metaclass
  _OBJC_CLASS_$__TtCs12_SwiftObject, // superclass
  __objc_empty_cache, // cache
  0x0, // vtable
  __objc_class__TtC9swift_cmd7Printer_data+1 // data
  }

There's a slight difference here, it seems that the final pointer, the object data pointer, actually points to an offset from the beginning of the objcclassTtC9swift_cmd7Prointer_data structure. If we take a look at that address, we find this:

__objc_class__TtC9swift_cmd7Printer_data:
  struct __objc_data {
    0x80, // flags
    16, // instance start
    32, // instance size
    0x0,
    0x0, // ivar layout
    aTtc9swiftcmd7p, // name
    0x0, // base methods
    0x0, // base protocols
    __objc_class__TtC9swift_cmd7Printer_ivars, // ivars
    0x0, // weak ivar layout
    0x0 // base properties
  }

Okay, so far so good right? Very similar to what we've seen in Objective-C, even with the offset. But look a little closer — there's no corresponding list of methods. Uh oh.

Well, we know that methods are associated with class instantiations somehow. But how? Well, let's take a look at the procedures defined in the executable.

Hopper gives us a list of 29 procedures. The two we're interested in are:

  • _$s9swift_cmd7PrinterC8printMsgyyF  
  • _$s9swift_cmd7PrinterC11printString7messageySS_tF 

How do I know? Well, even though the swift-demangle utility has yet to catch up with the name mangling in Swift 5, if you look closely you can see the names of the methods we're interested in embedded in this procedure names. Let's take a look at $s9swiftcmd7PrinterC11printString7messageySS_tF — it's the method we call, and if you take a look at the Swift implementation you can see it calls printMsg():

func printString(message: String) {
  str_to_print = message
  printMsg()
}

Perhaps it'll give us a clue as to how methods are defined on classes.

Here's the disassembly:

_$s9swift_cmd7PrinterC11printString7messageySS_tF:
  push rbp
  mov rbp, rsp
  push r13
  sub rsp, 0x48
  xorps xmm0, xmm0
  movaps xmmword [rbp+var_20], xmm0
  mov qword [rbp+var_28], 0x0
  mov qword [rbp+var_20], rdi
  mov qword [rbp+var_18], rsi
  mov qword [rbp+var_28], r13
  mov qword [rbp+var_30], rdi
  mov rdi, rsi
  mov qword [rbp+var_38], rsi
  mov qword [rbp+var_40], r13
  call imp___stubs__swift_bridgeObjectRetain ; swift_bridgeObjectRetain
  mov rsi, qword [rbp+var_40]
  mov rdi, qword [rsi]
  mov rdi, qword [rdi+0x60]
  mov r13, qword [rbp+var_30]
  mov qword [rbp+var_48], rdi
  mov rdi, r13
  mov rsi, qword [rbp+var_38]
  mov r13, qword [rbp+var_40]
  mov rcx, qword [rbp+var_48]
  mov qword [rbp+var_50], rax
  call rcx
  mov rax, qword [rbp+var_40]
  mov rcx, qword [rax]
  mov rcx, qword [rcx+0x78]
  mov r13, rax
  call rcx
  add rsp, 0x48
  pop r13
  pop rbp
  ret

We have two CALL opcodes. The first calls out to an external function, bridgeObjectRetain(). That's not really what we're interested in, so let's take a look at the second:

mov rcx, qword [rbp+var_48]
mov qword [rbp+var_50], rax
call rcx

The second CALL references the RCX register, which is loaded with an address from the stack. Yes, from the stack. This is a MAJOR change from Objective-C, and we'll need to start up LLDB to look at this a bit more closely.

Originally published by Christopher Lamb at dzone.com

------------------------------------------------------------------------------------------------------------------------------------------

Follow great articles on Twitter


Learn More

☞ iOS 12 & Swift - The Complete iOS App Development Bootcamp

☞ Learn Swift 4: From Beginner to Advanced

☞ Creating an iOS app with user presence using Node.js and Swift

☞ Learn Swift 4 for Beginners

☞ What’s new in Swift 5.0?

#swift

What is GEEK

Buddha Community

Method Internals in Swift 5.0
Houston  Sipes

Houston Sipes

1600430400

10 Free Online Resources To Learn Swift Language

Swift is a fast and efficient general-purpose programming language that provides real-time feedback and can be seamlessly incorporated into existing Objective-C code. This is why developers are able to write safer, more reliable code while saving time. It aims to be the best language that can be used for various purposes ranging from systems programming to mobile as well as desktop apps and scaling up to cloud services.

Below here, we list down the 10 best online resources to learn Swift language.

(The list is in no particular order)

#developers corner #free online resources to learn swift language #learn swift #learn swift free #learn swift online free #resources to learn swift #swift language #swift programming

Top Swift Development Companies | Top Swift Developers - TopDevelopers.co

A thoroughly researched list of top Swift developers with ratings & reviews to help find the best Swift development companies around the world.

#swift development service providers #best swift development companies #top swift development companies #swift development solutions #top swift developers #swift

Hire Dedicated Swift Developers

Want to create a native iOS application for your Startup?

Hire Dedicated Swift Developers for end-to-end services like development, migration, upgrade, testing, and support & maintenance. Trust HourlyDeveloper.io our Swift development team for iOS device apps that are high on performance and security.

Consult with experts:- https://bit.ly/2C5M6cz

#hire dedicated swift developers #swift developers #swift development company #swift development services #swift development #swift

Best Swift App Development Company

Hire an Exceptional Swift App Developer from Mobile App Development India. Maadi has a dedicated Swift App Development team that is superiorly talented and builds highly functional, cost-effective mobile apps with error-free coding.

Contact: https://www.mobile-app-development-india.com/swift-app-development/

#swift ios app development india #hire swift programmer india #swift ios development #apple swift app development #swift mobile app development #swift app development

Ethen Ellen

1619519725

Immediate $olution to Fix AOL Blerk Error Code 5 with easy instructions

This is image title

AOL Email is one of the leading web email services. It has a number of features who access easily at any place. Through this, you can easily share messages, documents or files, etc.AOL Blerk Error is not a big issue. It is a temporary error and it occurs when there is an issue in loading messages from the AOL server. If your mind is stuck, How to Resolve or Fix AOL Blerk Error Code 5? Here, In this article, we mentioned troubleshooting steps to fix AOL Blerk Error Code 5.

What are the causes of AOL Blerk Error Code 5?

AOL mail usually presents an AOL Blerk Error 5 after the AOL connection details have been entered. meaning. Your password and your username. This error is usually found in words! Or 'BLERK! Error 5 Authentication problem, 'Your sign-in has been received.

Some of the reasons for the error are as follows:
• Internet browser configuration problem

• Saved erroneous bookmark addresses

• browser cache or cookie

• An AOL Desktop Gold technical error.
How to Fix AOL Mail Blerk Error 5 in a Simple Way

This type of error is mostly due to your browser settings or the use of outdated, obsolete software. Users should remember that the steps to solve problems vary, depending on the browser you are using. Here are the steps to fix the mistake, check your browser and follow the steps.

Internet Explorer: Make sure you use the most recent web browser version. Open a new window and follow the “Tools> Web Options> Security> Internet Zone” thread. Activate ‘Safeguard Mode’ and follow the steps to include AOL Mail in the list of assured websites. Start the browser again to save changes and run Internet Explorer without additional information.
Firefox Mozilla: Open a new Firefox window and press Menu. To start the browser in safe mode, disable the add-on and choose the option to restart Firefox. You can see two options in the dialog box. Use the “Start in Safe Mode” option to disable all themes and extensions. The browser also turns off the hardware speed and resets the toolbar. You should be able to execute AOL mail when this happens.

Google Chrome: Update to the latest version of Chrome. Open the browser and go to the Advanced Options section. Go to ‘Security and Privacy’ and close the appropriate add-ons. Once the browsing history is deleted, the password, cookies saved and the cache will be cleared. Restart your system and try to log in to your AOL account with a new window.

Safari: Some pop-up windows block AOL mail when it comes to Safari and causes authentication issues. To fix the error, use Safari Security Preferences to enable the pop-up window and disable the security warning.

If you see, even when you change the required browser settings, the black error will not disappear, you can consult a skilled professional and see all the AOL email customer support numbers.

Get Connect to Fix Blerk Error Even After Clearing Cache & Cookies?
Somehow you can contact AOL technical support directly and get immediate help if you still get the error. Call +1(888)857-5157 to receive assistance from the AOL technical support team.

Source: https://email-expert247.blogspot.com/2021/04/immediate-olution-to-fix-aol-blerk.html “How to Resolve or Fix AOL Blerk Error Code 5”)**? Here, In this article, we mentioned troubleshooting steps to fix AOL Blerk Error Code 5.

What are the causes of AOL Blerk Error Code 5?

AOL mail usually presents an AOL Blerk Error 5 after the AOL connection details have been entered. meaning. Your password and your username. This error is usually found in words! Or 'BLERK! Error 5 Authentication problem, 'Your sign-in has been received.

Some of the reasons for the error are as follows:
• Internet browser configuration problem

• Saved erroneous bookmark addresses

• browser cache or cookie

• An AOL Desktop Gold technical error.
How to Fix AOL Mail Blerk Error 5 in a Simple Way

This type of error is mostly due to your browser settings or the use of outdated, obsolete software. Users should remember that the steps to solve problems vary, depending on the browser you are using. Here are the steps to fix the mistake, check your browser and follow the steps.

  1. Internet Explorer: Make sure you use the most recent web browser version. Open a new window and follow the “Tools> Web Options> Security> Internet Zone” thread. Activate ‘Safeguard Mode’ and follow the steps to include AOL Mail in the list of assured websites. Start the browser again to save changes and run Internet Explorer without additional information.

  2. Firefox Mozilla: Open a new Firefox window and press Menu. To start the browser in safe mode, disable the add-on and choose the option to restart Firefox. You can see two options in the dialog box. Use the “Start in Safe Mode” option to disable all themes and extensions. The browser also turns off the hardware speed and resets the toolbar. You should be able to execute AOL mail when this happens.

  3. Google Chrome: Update to the latest version of Chrome. Open the browser and go to the Advanced Options section. Go to ‘Security and Privacy’ and close the appropriate add-ons. Once the browsing history is deleted, the password, cookies saved and the cache will be cleared. Restart your system and try to log in to your AOL account with a new window.

  4. Safari: Some pop-up windows block AOL mail when it comes to Safari and causes authentication issues. To fix the error, use Safari Security Preferences to enable the pop-up window and disable the security warning.

If you see, even when you change the required browser settings, the black error will not disappear, you can consult a skilled professional and see all the AOL email customer support numbers.

Get Connect to Fix Blerk Error Even After Clearing Cache & Cookies?

Somehow you can contact AOL technical support directly and get immediate help if you still get the error. Call +1(888)857-5157 to receive assistance from the AOL technical support team.

Source: https://email-expert247.blogspot.com/2021/04/immediate-olution-to-fix-aol-blerk.html

#aol blerk error code 5 #aol blerk error 5 #aol mail blerk error code 5 #aol mail blerk error 5 #aol error code 5 #aol error 5