Objective-C is an object-oriented programming language that uses message passing to communicate between objects. Objects are represented as C structs with a pointer to their class. The class struct contains metadata about the class like its name, methods, and properties. Objective-C uses a dynamic runtime that allows objects to be modified at runtime via mechanisms like method swizzling and isa swizzling.
Here are the key points about classes and metaclasses in Objective-C:
- Every Objective-C class is an instance of another class called its metaclass. The metaclass allows the class to receive and respond to messages.
- The root class is called Class. All other classes are subclasses of Class.
- When you send a message to a class like [MyClass foo], it is actually sending the message to the metaclass of MyClass, not to MyClass itself. The metaclass handles class methods and behaviors.
- The isa pointer in the class structure points to the metaclass, not the superclass. This allows classes to behave like objects and receive messages.
- So in summary, classes are objects (instances
The document provides an overview of the Objective-C runtime and how it can be used in practice. It begins with introductions and then covers key topics like what the runtime is, how it supports object-oriented features in Objective-C, and how Foundation provides a simpler interface to interact with the runtime. It then demonstrates various runtime capabilities like dealing with classes, protocols, messages, and dynamic messaging. It also covers more advanced techniques like lazy method resolution, forwarding, swizzling, dynamic class generation, and property generation. Code examples are provided to demonstrate many of these runtime features in practice.
This document provides an overview of Typescript tips and tricks. It covers topics like using Typescript to write modern JavaScript, module systems, import/export syntax, decorators, union and intersection types, null checks, mixins, and more. The document is intended to cover useful details about Typescript beyond an introductory level. Code examples are provided to demonstrate many of the language features.
This document discusses invokedynamic and the JSR-292 API. It provides an overview of invokedynamic, how it is used in the JVM to support multiple languages, and how it works with MethodHandles and CallSites. It also summarizes the key classes and methods in the JSR-292 API, including MethodHandles, MethodHandles.Lookup, MethodType, and how they can be used to dynamically call methods via MethodHandles.
The presentation helps us in understanding the different concepts associated with TypeScript. What is TypeScript? Why is TypeScript used and the different applications of TypeScript. For more information you can simply visit: http://mobile.folio3.com/
TypeScript is an open-source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript, and adds static typing and class-based object-oriented programming to the language. Anders Hejlsberg, the chief architect of C# and creator of Delphi and Turbo Pascal, worked on the development of TypeScript. TypeScript can be used to build JavaScript applications for execution on the client-side or server-side (Node.js). Some key features of TypeScript include static typing, support for type definitions of existing JavaScript libraries, and support for object-oriented programming.
JavaScript - An Introduction is a beginner's guide to JavaScript. It starts with very basic level and goes to intermediate level. You'll be introduced with every language constructs, Event handling, Form handling and AJAX which is supported by JavaScript with XMLHttpRequest object. This XHR object is discussed in enough detail so that you can understand how the underlying AJAX functionality works in jQuery. At the end it discusses advance concepts and library build on/around JavaScript.
This document provides an overview of the Dart programming language created by Google. It discusses Dart's structure as a new programming language with its own runtime environment and tools. Key features covered include Dart's static yet dynamic typing, use of classes and objects, namespaces, isolates for concurrency, and snapshots for faster startups. The document also provides code examples demonstrating Dart's syntax and how it handles concepts like generics differently than other languages like Java.
Mastering Java Bytecode With ASM - 33rd degree, 2012Anton Arhipov
The document discusses bytecode and the ASM library for manipulating Java bytecode. It provides an overview of bytecode structure and instructions. ASM is introduced as a low-level API for working with bytecode using visitors and nodes. Examples are given for generating bytecode using ASM, such as creating a ClassWriter, visiting classes, fields and methods, and generating instructions.
This document provides an overview of Objective-C, including key concepts like runtime, objects, classes, memory management, class interfaces and implementations, protocols, properties, and selectors. It discusses how Objective-C performs tasks at runtime and uses object-oriented programming principles. Methods are invoked by sending object messages, and classes define object types. Memory is managed using reference counting or a garbage collector. The document also provides examples of class interfaces and implementations, as well as using properties and protocols.
Lambda: A Peek Under The Hood - Brian GoetzJAX London
This is a *highly technical* session on the details of how Lambda expressions are implemented in the Java language, presented by Java Language Architect Brian Goetz
Not so long ago Microsoft announced a new language trageting on front-end developers. Everybody's reaction was like: Why?!! Is it just Microsoft darting back to Google?!
So, why a new language? JavaScript has its bad parts. Mostly you can avoid them or workaraund. You can emulate class-based OOP style, modules, scoping and even run-time typing. But that is doomed to be clumsy. That's not in the language design. Google has pointed out these flaws, provided a new language and failed. Will the story of TypeScript be any different?
The document provides an overview of JavaScript programming. It discusses the history and components of JavaScript, including ECMAScript, the DOM, and BOM. It also covers JavaScript basics like syntax, data types, operators, and functions. Finally, it introduces object-oriented concepts in JavaScript like prototype-based programming and early vs. late binding.
Android JNI/NDK allows developers to use native code like C/C++ code in Android applications. It does this through the Java Native Interface (JNI) which provides a way to create Java objects and call Java methods from native code. The Native Development Kit (NDK) includes tools to compile C/C++ code for the Android platform. JNI allows accessing native methods and data types from Java code. It provides functions for loading native libraries, registering native methods, and manipulating objects, strings, classes and fields between the Java and native environments. Exceptions must be handled when using JNI to ensure stable applications.
This document discusses building a Java tracer using bytecode, JNI, JVMTI and ASM. It covers Java bytecode format, using JNI and JVMTI to build C extensions that interface with the JVM, ASM for bytecode analysis and manipulation, and a demo of using these technologies to trace a "Hello, World" program. It also outlines areas for further work on the tracer and takes questions.
Objective-C is an object-oriented programming language based on C. It uses message passing to call methods similarly to Smalltalk. The syntax is based on C with the addition of object-oriented features like classes, inheritance, polymorphism, and dynamic typing. Memory management in Objective-C applications is handled automatically by the compiler through reference counting. Categories allow extending classes at runtime by adding new methods.
The document provides an overview of JavaScript, covering what it is, its basics, functions, objects, prototypes, scope, asynchronous JavaScript, JSON, debugging tools, performance, events, error handling, and the future of JavaScript. It discusses that JavaScript is an object-oriented scripting language used in web pages that is not tied to specific browsers but makes use of the DOM, BOM, and ECMAScript standards. It also summarizes some of JavaScript's core features like functions, objects, prototypes, and more.
The document provides an introduction to basic Javascript concepts such as variables, scopes, closures, prototypes, and object-oriented programming principles including inheritance and namespaces over several sections; it also discusses how Javascript code is executed in an execution context and how functions, closures, and prototypes work together to enable OOP functionality in Javascript.
Kotlin is a statically typed programming language that is 100% interoperable with Java. It aims to combine object-oriented and functional programming features and to be more concise than Java. Some key features of Kotlin include type inference, properties that replace getter/setter methods, higher-order functions, lambdas, and coroutines. Using Kotlin can increase developer productivity through less code, fewer errors, and clearer syntax. It also allows existing Java code to remain unchanged while new features are developed in Kotlin. Integrating Kotlin into a project requires adding dependencies and plugins, setting up tooling, and initially targeting a small component for parallel development in both languages.
Understanding bytecode and what bytecode is likely to be generated by a Java compiler helps the Java programmer in the same way that knowledge of assembler helps the C or C++ programmer. Java bytecode is the form of instructions that Java virtual machine executes. This knowledge is crucial when debugging and doing performance and memory usage tuning. The presenter will share his knowledge on what bytecode means for your platform and how to create compiler while using some awesome tools.
The document provides an overview of fundamental JavaScript concepts such as variables, data types, operators, control structures, functions, and objects. It also covers DOM manipulation and interacting with HTML elements. Code examples are provided to demonstrate JavaScript syntax and how to define and call functions, work with arrays and objects, and select and modify elements of a web page.
This document provides an overview of the Dart programming language. It discusses why Dart was created by Google, its key design goals around flexibility, familiarity, and performance. It also summarizes Dart's main features like optional typing, classes and interfaces, libraries, and futures. The document encourages attendees to get involved in the technical preview by visiting the Dart website, joining mailing lists, and using online resources.
Blocks allow passing code as a parameter or return value from functions. They capture the context in which they are defined. Grand Central Dispatch (GCD) simplifies concurrent programming using dispatch queues, which can execute blocks asynchronously or synchronously, and dispatch sources which attach blocks to system events. Dispatch groups and semaphores help coordinate work across dispatch queues.
There are several JavaScript libraries available in the world of web programming. And, as the usage and complexity is increasing day by day, sometimes it becomes very difficult and confusing to understand and create modules using those libraries, especially for those having strong background of Object Oriented Languages.
So this one hour session will make an effort to go into the very basics of JavaScript and put a base for writing modular JavaScript code.
Android Developer Group Poznań - Kotlin for Android developers
STXInsider example project in Kotlin:
https://github.com/kosiara/stx-insider
Kotlin - one of the popular programming languages built on top of Java that runs on JVM. Thanks to JetBrains support and excellent IDE integration, it’s an ideal choice for Android development. 100% Java compatibility, interoperability and no runtime overhead is just the beginning of a long list of strengths. Kotlin is supposed to be a subset of SCALA, has clear benefits for developers on one hand and keeps short compile times on the other.
As a mobile team we got interested in Kotlin a few months before its final release which gave us time to test it thoroughly before production use. The language has some clear advantages for an Android programmer - it enables migration from Java projects that have been under development for some time already. Java&Kotlin coexistence simplifies Kotlin introduction as only new functionality is written in JetBrain’s new language leaving all the legacy code untouched.
Transitioning gives the developer an opportunity to use lambdas, new syntax for data objects, extension functions to easily expand Android SDK’s classes functionality and infix notation to write DSL-like structures. Almost all the libraries you use today will work with Kotlin thanks to 100% Java compatibility. The same is true for Android SDK classes - all of them will seamlessly work with the new programming language. Kotlin gives you more choice when it comes to reflection, creating documentation and being null-pointer safe. Android works great with it out of the box so you won’t need to change your development habits.
Our production project in Kotlin turned out to be a success after 4 months of development. We had 0 bugs related to Kotlin as a programming language. Our code footprint is almost 30% smaller thanks to JetBrain’s, we benefit from nullpointer safety, closures, translated enums, data objects and use infix notation for logging and displaying Snackbars.
===========
In this presentation you'll find basic use cases, syntax, structures and patterns. Later on Kotlin is presented in Android context. Simple project structure, imports and Kotlin usage with Android SDK is explained. In the end cost of Kotlin compilation is presented and the language is compared to SCALA and SWIFT.
We look at the positive impact new syntax can have on boilerplate removal and readability improvement.
Kotlin really shines in Android development when one looks at “Enum translation”, “Extension functions”, “SAM conversions”, “Infix notation”, “Closures” and “Fluent interfaces” applied to lists. The talk, however, compares language-specifics of Java & Kotlin in terms of “Type Variance”, “Generics” and “IDE tools” as well.
This document provides an overview of TypeScript, including:
- What TypeScript is and how it supports features like interfaces, classes, and subclasses
- How TypeScript uses a compiler to provide type checking and transpiles code to JavaScript
- Examples of using basic TypeScript syntax like types, functions, classes, and interfaces
- How to set up a TypeScript development environment and use the tsc compiler
- Popular IDEs and resources for learning more about TypeScript
This summary provides an overview of the key points about Groovy 2.0 discussed in the document:
1. Groovy 2.0 features a more modular architecture with smaller JAR files for individual features, as well as the ability to create custom extension modules.
2. It includes support for Java 7 features like binary literals, underscores in literals, and multicatch exceptions.
3. The new static type checking functionality in Groovy 2.0 aims to catch errors like typos, missing methods, and wrong assignments at compile time rather than runtime.
This document provides an overview of JavaScript 101. It discusses:
1. The roots of JavaScript including its development by Brendan Eich at Netscape in 1995 to add interactivity to web pages.
2. Core concepts of JavaScript including the DOM, objects, prototype-oriented programming, functions, timing events, scopes, and closures.
3. Advanced topics like callbacks, events, AJAX, performance factors, security considerations, and popular extension libraries.
The document provides examples of JavaScript code to illustrate key points and concepts. It aims to give readers foundational knowledge to understand the basics of JavaScript before exploring further advances.
The document discusses new features in Visual Studio 2010, C# 4.0, and Visual Basic 10 including functional, concise, and declarative features. It covers LINQ and how it allows declarative code that is more readable. Other topics include the evolution of C# and Visual Basic with new versions adding dynamic and concurrent features. The document also discusses the Dynamic Language Runtime and how it allows dynamic programming and interoperability between dynamic languages and .NET languages.
This document provides an overview of C# programming and SQL. It introduces C#, its syntax derived from C/C++, and what can be done with C# including Windows and web applications. It also covers SQL for manipulating database records, including INSERT, UPDATE, DELETE statements. Sample SQL code is provided to insert, update, modify records in a phonebook table. Key things to remember are enclosing string data in single quotes, separating values with commas, ending statements with semicolons, and using Pascal casing.
Mastering Java Bytecode With ASM - 33rd degree, 2012Anton Arhipov
The document discusses bytecode and the ASM library for manipulating Java bytecode. It provides an overview of bytecode structure and instructions. ASM is introduced as a low-level API for working with bytecode using visitors and nodes. Examples are given for generating bytecode using ASM, such as creating a ClassWriter, visiting classes, fields and methods, and generating instructions.
This document provides an overview of Objective-C, including key concepts like runtime, objects, classes, memory management, class interfaces and implementations, protocols, properties, and selectors. It discusses how Objective-C performs tasks at runtime and uses object-oriented programming principles. Methods are invoked by sending object messages, and classes define object types. Memory is managed using reference counting or a garbage collector. The document also provides examples of class interfaces and implementations, as well as using properties and protocols.
Lambda: A Peek Under The Hood - Brian GoetzJAX London
This is a *highly technical* session on the details of how Lambda expressions are implemented in the Java language, presented by Java Language Architect Brian Goetz
Not so long ago Microsoft announced a new language trageting on front-end developers. Everybody's reaction was like: Why?!! Is it just Microsoft darting back to Google?!
So, why a new language? JavaScript has its bad parts. Mostly you can avoid them or workaraund. You can emulate class-based OOP style, modules, scoping and even run-time typing. But that is doomed to be clumsy. That's not in the language design. Google has pointed out these flaws, provided a new language and failed. Will the story of TypeScript be any different?
The document provides an overview of JavaScript programming. It discusses the history and components of JavaScript, including ECMAScript, the DOM, and BOM. It also covers JavaScript basics like syntax, data types, operators, and functions. Finally, it introduces object-oriented concepts in JavaScript like prototype-based programming and early vs. late binding.
Android JNI/NDK allows developers to use native code like C/C++ code in Android applications. It does this through the Java Native Interface (JNI) which provides a way to create Java objects and call Java methods from native code. The Native Development Kit (NDK) includes tools to compile C/C++ code for the Android platform. JNI allows accessing native methods and data types from Java code. It provides functions for loading native libraries, registering native methods, and manipulating objects, strings, classes and fields between the Java and native environments. Exceptions must be handled when using JNI to ensure stable applications.
This document discusses building a Java tracer using bytecode, JNI, JVMTI and ASM. It covers Java bytecode format, using JNI and JVMTI to build C extensions that interface with the JVM, ASM for bytecode analysis and manipulation, and a demo of using these technologies to trace a "Hello, World" program. It also outlines areas for further work on the tracer and takes questions.
Objective-C is an object-oriented programming language based on C. It uses message passing to call methods similarly to Smalltalk. The syntax is based on C with the addition of object-oriented features like classes, inheritance, polymorphism, and dynamic typing. Memory management in Objective-C applications is handled automatically by the compiler through reference counting. Categories allow extending classes at runtime by adding new methods.
The document provides an overview of JavaScript, covering what it is, its basics, functions, objects, prototypes, scope, asynchronous JavaScript, JSON, debugging tools, performance, events, error handling, and the future of JavaScript. It discusses that JavaScript is an object-oriented scripting language used in web pages that is not tied to specific browsers but makes use of the DOM, BOM, and ECMAScript standards. It also summarizes some of JavaScript's core features like functions, objects, prototypes, and more.
The document provides an introduction to basic Javascript concepts such as variables, scopes, closures, prototypes, and object-oriented programming principles including inheritance and namespaces over several sections; it also discusses how Javascript code is executed in an execution context and how functions, closures, and prototypes work together to enable OOP functionality in Javascript.
Kotlin is a statically typed programming language that is 100% interoperable with Java. It aims to combine object-oriented and functional programming features and to be more concise than Java. Some key features of Kotlin include type inference, properties that replace getter/setter methods, higher-order functions, lambdas, and coroutines. Using Kotlin can increase developer productivity through less code, fewer errors, and clearer syntax. It also allows existing Java code to remain unchanged while new features are developed in Kotlin. Integrating Kotlin into a project requires adding dependencies and plugins, setting up tooling, and initially targeting a small component for parallel development in both languages.
Understanding bytecode and what bytecode is likely to be generated by a Java compiler helps the Java programmer in the same way that knowledge of assembler helps the C or C++ programmer. Java bytecode is the form of instructions that Java virtual machine executes. This knowledge is crucial when debugging and doing performance and memory usage tuning. The presenter will share his knowledge on what bytecode means for your platform and how to create compiler while using some awesome tools.
The document provides an overview of fundamental JavaScript concepts such as variables, data types, operators, control structures, functions, and objects. It also covers DOM manipulation and interacting with HTML elements. Code examples are provided to demonstrate JavaScript syntax and how to define and call functions, work with arrays and objects, and select and modify elements of a web page.
This document provides an overview of the Dart programming language. It discusses why Dart was created by Google, its key design goals around flexibility, familiarity, and performance. It also summarizes Dart's main features like optional typing, classes and interfaces, libraries, and futures. The document encourages attendees to get involved in the technical preview by visiting the Dart website, joining mailing lists, and using online resources.
Blocks allow passing code as a parameter or return value from functions. They capture the context in which they are defined. Grand Central Dispatch (GCD) simplifies concurrent programming using dispatch queues, which can execute blocks asynchronously or synchronously, and dispatch sources which attach blocks to system events. Dispatch groups and semaphores help coordinate work across dispatch queues.
There are several JavaScript libraries available in the world of web programming. And, as the usage and complexity is increasing day by day, sometimes it becomes very difficult and confusing to understand and create modules using those libraries, especially for those having strong background of Object Oriented Languages.
So this one hour session will make an effort to go into the very basics of JavaScript and put a base for writing modular JavaScript code.
Android Developer Group Poznań - Kotlin for Android developers
STXInsider example project in Kotlin:
https://github.com/kosiara/stx-insider
Kotlin - one of the popular programming languages built on top of Java that runs on JVM. Thanks to JetBrains support and excellent IDE integration, it’s an ideal choice for Android development. 100% Java compatibility, interoperability and no runtime overhead is just the beginning of a long list of strengths. Kotlin is supposed to be a subset of SCALA, has clear benefits for developers on one hand and keeps short compile times on the other.
As a mobile team we got interested in Kotlin a few months before its final release which gave us time to test it thoroughly before production use. The language has some clear advantages for an Android programmer - it enables migration from Java projects that have been under development for some time already. Java&Kotlin coexistence simplifies Kotlin introduction as only new functionality is written in JetBrain’s new language leaving all the legacy code untouched.
Transitioning gives the developer an opportunity to use lambdas, new syntax for data objects, extension functions to easily expand Android SDK’s classes functionality and infix notation to write DSL-like structures. Almost all the libraries you use today will work with Kotlin thanks to 100% Java compatibility. The same is true for Android SDK classes - all of them will seamlessly work with the new programming language. Kotlin gives you more choice when it comes to reflection, creating documentation and being null-pointer safe. Android works great with it out of the box so you won’t need to change your development habits.
Our production project in Kotlin turned out to be a success after 4 months of development. We had 0 bugs related to Kotlin as a programming language. Our code footprint is almost 30% smaller thanks to JetBrain’s, we benefit from nullpointer safety, closures, translated enums, data objects and use infix notation for logging and displaying Snackbars.
===========
In this presentation you'll find basic use cases, syntax, structures and patterns. Later on Kotlin is presented in Android context. Simple project structure, imports and Kotlin usage with Android SDK is explained. In the end cost of Kotlin compilation is presented and the language is compared to SCALA and SWIFT.
We look at the positive impact new syntax can have on boilerplate removal and readability improvement.
Kotlin really shines in Android development when one looks at “Enum translation”, “Extension functions”, “SAM conversions”, “Infix notation”, “Closures” and “Fluent interfaces” applied to lists. The talk, however, compares language-specifics of Java & Kotlin in terms of “Type Variance”, “Generics” and “IDE tools” as well.
This document provides an overview of TypeScript, including:
- What TypeScript is and how it supports features like interfaces, classes, and subclasses
- How TypeScript uses a compiler to provide type checking and transpiles code to JavaScript
- Examples of using basic TypeScript syntax like types, functions, classes, and interfaces
- How to set up a TypeScript development environment and use the tsc compiler
- Popular IDEs and resources for learning more about TypeScript
This summary provides an overview of the key points about Groovy 2.0 discussed in the document:
1. Groovy 2.0 features a more modular architecture with smaller JAR files for individual features, as well as the ability to create custom extension modules.
2. It includes support for Java 7 features like binary literals, underscores in literals, and multicatch exceptions.
3. The new static type checking functionality in Groovy 2.0 aims to catch errors like typos, missing methods, and wrong assignments at compile time rather than runtime.
This document provides an overview of JavaScript 101. It discusses:
1. The roots of JavaScript including its development by Brendan Eich at Netscape in 1995 to add interactivity to web pages.
2. Core concepts of JavaScript including the DOM, objects, prototype-oriented programming, functions, timing events, scopes, and closures.
3. Advanced topics like callbacks, events, AJAX, performance factors, security considerations, and popular extension libraries.
The document provides examples of JavaScript code to illustrate key points and concepts. It aims to give readers foundational knowledge to understand the basics of JavaScript before exploring further advances.
The document discusses new features in Visual Studio 2010, C# 4.0, and Visual Basic 10 including functional, concise, and declarative features. It covers LINQ and how it allows declarative code that is more readable. Other topics include the evolution of C# and Visual Basic with new versions adding dynamic and concurrent features. The document also discusses the Dynamic Language Runtime and how it allows dynamic programming and interoperability between dynamic languages and .NET languages.
This document provides an overview of C# programming and SQL. It introduces C#, its syntax derived from C/C++, and what can be done with C# including Windows and web applications. It also covers SQL for manipulating database records, including INSERT, UPDATE, DELETE statements. Sample SQL code is provided to insert, update, modify records in a phonebook table. Key things to remember are enclosing string data in single quotes, separating values with commas, ending statements with semicolons, and using Pascal casing.
This document provides an introduction to C# programming. It was created by Naruemon Soonthong for educational purposes. The document contains information on the basics of C# and can be found online at http://krufern32101.blogspot.com.
This document provides an overview of basic C# syntax and concepts such as variables, expressions, operators, and comments. It defines C# code structure and blocks and explains how to declare and name variables to store data of different types. The document also describes expressions as combinations of variables and operators, and covers common operator types including arithmetic, relational, logical, and assignment operators. It provides examples of using operators and the order of operator precedence.
This presentation provides an overview of object-oriented programming (OOP). It discusses key OOP concepts including objects, classes, encapsulation, inheritance, polymorphism, and message passing. Objects are instances of classes that have both data and behaviors. Classes define common properties and methods for objects. Encapsulation binds together an object's data and methods, while inheritance establishes a hierarchy where derived classes inherit from base classes. Polymorphism allows the same message to be interpreted differently, and message passing facilitates communication between objects.
This document provides an overview of C Sharp programming, including introductions to core concepts like classes, the .NET framework, and object-oriented programming principles. It covers language basics, syntax, variables, operators, and more. Sections are devoted to key topics such as console programming, Windows forms, and advanced object-oriented concepts. The document serves as a general reference for C Sharp programming that describes the language and provides examples.
C# is a component-oriented programming language that builds on the .NET framework. It has a familiar C-like syntax that is easy for developers familiar with C, C++, Java, and Visual Basic to adopt. C# is fully object-oriented and optimized for building .NET applications. Everything in C# belongs to a class, with basic data types including integers, floats, booleans, characters, and strings. C# supports common programming constructs like variables, conditional statements, loops, methods, and classes. C# can be easily combined with ASP.NET for building web applications in a powerful, fast, and high-level way.
This is a presentation I did for the Cedar Rapids .NET User Group (CRineta.org). It was intended to present object oriented concepts and their application in .NET and C#.
The document discusses an agenda covering the .NET platform and Visual Studio. It will cover the .NET framework, an introduction to C#, object-oriented programming in C#, assemblies and modules, and sample applications. It then discusses the .NET platform, Visual Studio IDE, execution in .NET, and code conversion to C#. Key aspects of C# like components, data types, arrays, and assemblies are defined.
The document provides information about C and C Sharp programming languages. It discusses the history, features, data types, loops, conditional statements, functions, arrays, pointers, object-oriented concepts like inheritance, encapsulation, polymorphism in both the languages. It also highlights some advantages of C Sharp over C like automatic memory management, no need of header files etc.
Object oriented programming (OOP) addresses limitations of procedural programming by dividing programs into objects that encapsulate both data and behaviors. OOP supports features like inheritance, polymorphism, and abstraction. Inheritance allows new classes to inherit attributes and behaviors from parent classes, polymorphism allows the same message to be interpreted differently depending on the object receiving it, and abstraction focuses on essential characteristics without implementation details. These features help make programs more modular, reusable, and maintainable.
The document provides an overview of the basics of C# 2008 .NET 3.0/3.5, including the basic structure of a C# program, namespaces, classes, methods, variables, data types, operators, flow control, arrays, namespaces, console input/output, and comments. It discusses key concepts such as object-oriented programming fundamentals, console applications in Visual Studio 2008, and more advanced topics such as checked and unchecked operators.
This document provides an introduction and overview of C# programming and SQL. It discusses key aspects of C#, its uses in Windows, web, and web service applications. It also covers SQL fundamentals like retrieving, inserting, updating, and deleting records. The document includes examples of SQL statements like INSERT, UPDATE, DELETE, and SELECT and highlights best practices like enclosing string values in single quotes and ending statements with semicolons.
The document discusses key concepts in object-oriented programming including objects, classes, messages, and requirements for object-oriented languages. An object is a bundle of related variables and methods that can model real-world things. A class defines common variables and methods for objects of a certain kind. Objects communicate by sending messages to each other specifying a method name and parameters. For a language to be object-oriented, it must support encapsulation, inheritance, and dynamic binding.
The document provides an overview of the C# programming language. It discusses that C# is an object-oriented language developed by Microsoft for building applications on the .NET platform. Some key points covered include:
- C# is derived from C/C++ but simplifies aspects of these languages. It supports features like automatic memory management, events, delegates, and object-oriented programming principles.
- The .NET Framework provides the runtime environment for C# and other .NET languages. It includes the Common Language Runtime (CLR) for memory management, security, and other services.
- C# code is compiled to an intermediate language (IL) that is executed by the CLR on any .NET-compatible platform.
The document provides an overview of C++ vs C# by Shubhra Chauhan. It discusses the key object-oriented programming concepts like classes, objects, inheritance, polymorphism, and how they are implemented in C++ and C#. It includes code examples to demonstrate class usage and inheritance in both languages. The document also compares some similarities and differences between C++ and C# like support for pointers, preprocessors, structures, and goto statements.
The document provides an overview of developing iOS applications including the required language (Objective-C), frameworks (Cocoa Touch), tools, and development process. It discusses setting up a Mac development environment, learning Objective-C syntax and concepts like classes, methods, properties, protocols, and the iOS application layers including Cocoa Touch.
Objective-C for iOS Application DevelopmentDhaval Kaneria
The document provides an introduction to Objective-C and iPhone development. It discusses key aspects of Objective-C including its syntax which extends C with object-oriented capabilities. Objective-C uses class definitions with interfaces and implementations. Programs create class instances that can receive messages to call methods. Classes can inherit from superclasses and support polymorphism. The document also outlines core concepts like memory management, frameworks for iOS development and examples of Hello World programs.
Никита Корчагин - Programming Apple iOS with Objective-CDataArt
This document provides an overview of programming iOS apps with Objective-C, including how to get started, the Objective-C and Swift languages, Model-View-Controller (MVC) pattern, differences between desktop and mobile development, and human interface guidelines. Key topics covered include installing the necessary software, understanding core Objective-C concepts like classes, methods, and memory management, using view controllers and the MVC pattern to structure apps, and important considerations for mobile like limited resources and touch interfaces.
Objective-C is an object-oriented language built on C that uses message passing. It is used for programming Mac and iOS apps. The document explains key Objective-C concepts like classes, properties, inheritance, initialization, and categories. It also recommends resources for learning more about MVC, delegation, blocks, KVO/KVC, the runtime, and other advanced Objective-C features.
This document provides an overview of an Objective-C lesson for Java developers. It discusses why Objective-C is important as the main language for developing Mac and iOS software. It also covers some key differences between Objective-C and Java like memory management, syntax involving properties and memory ownership. The document outlines concepts like classes, headers, imports and memory management in Objective-C.
The document provides an introduction to the Objective-C programming language. It discusses objects, classes, messaging between objects, and the Objective-C runtime system. It covers key concepts such as classes, inheritance, protocols, properties, categories and extensions, memory management, and threading. The document is intended for readers interested in programming with Objective-C or learning the basis of the Cocoa frameworks.
The document discusses how to code for accelerometer and Core Location in Objective-C. It provides code snippets for reading accelerometer data using UIAccelerometer and handling orientation changes. It also explains how to get the user's current location using the Core Location framework by initializing a CLLocationManager instance and setting a delegate to receive location updates.
Objective-C is an object-oriented programming language that is a superset of C. It was developed in the 1980s on top of C to provide object-oriented capabilities. Objective-C uses classes and messages to define methods and invoke behaviors on objects. Developers create classes with properties and methods to define behaviors and attributes for objects. Memory is managed through retain counts, and objects communicate by sending messages to each other to invoke methods.
The document provides an overview of topics to be covered in an iPhone application development course, including:
1. The course schedule covers Objective-C basics, the MVC design pattern, networking services like Facebook API and location-based services.
2. Resources for self-study include the Stanford iOS course, Apple documentation, and books like "iOS Programming: The Big Nerd Ranch Guide."
3. Today's topics are the iPhone SDK, Objective-C language basics, common foundation classes, and creating a first iPhone application.
iPhone, the next generation mobile platform has revolutionized the way one uses phones as it's a combination of a phone, an iPod and an internet device. The iPhone is a richer platform for application delivery due to an exponential growth and wide spread usage.
The critical factor, for a successful mobile application is the end user experience: application usability, reliability, and performance which the iPhone delivers in style. There are thousands of applications created by hundreds of developers for the iPhone. This kind of innovation helps you start developing the next generation of innovative mobile applications now.
Topics Covered
* Current State of iPhone Development
* Fast Track to Objective C
* Fast Track to XCode and Interface Builder
* Getting Productive using OR-Framework, Testing, Serialization
Munjal Budhabhatti is a senior solution developer at ThoughtWorks. He possesses over 10 years of experience in designing large-scale enterprise applications and has implemented innovative solutions for some of the largest microfinance, insurance and financial organizations. He loves writing well-designed enterprise applications using Agile processes. His article on "Test-Driven Development and Continuous Integration for Mobile Applications" was recently published in the Microsoft Architecture Journal.
Objective-C classes define blueprints for objects. A class describes common properties and behaviors for any instance of that class. Classes provide an interface that lists messages an object can receive and a implementation that contains executable code for each message. When building apps, most work involves customizing and combining framework classes with your own classes to provide unique functionality.
The document provides an overview of options for iOS development including HTML5, cross-platform frameworks like Titanium and PhoneGap, and native iOS development using Objective-C. HTML5 allows using existing web technologies but has limited hardware access and cross-browser issues. Cross-platform frameworks provide better hardware access but compatibility may vary. Native development using Objective-C offers the most control and best performance but only works on iOS. Xcode is used for native iOS development. An introduction to Objective-C covers classes, methods, and basic syntax similar to C with object-oriented additions.
The document provides an overview of iOS 5 development using Objective-C. It begins with introductions and contact information, then outlines the agenda which includes a review of Objective-C and iOS, an overview of new iOS 5 features, and a demonstration of the Lobstagram app. The document then discusses iOS development requirements and provides a 10 minute crash course on Objective-C, covering classes, methods, properties, and implementation.
This document provides an agenda for an iOS development training that covers Objective-C knowledge, the MVC pattern, and building a view-based application in Xcode. The topics include an introduction to iOS, the Objective-C language syntax including classes, objects, properties, and memory management, the model-view-controller pattern, and building an app using views, view controllers, navigation controllers, and common controls. The training aims to equip attendees with the skills needed to develop native iOS applications using Apple's SDK frameworks and development tools.
This document provides an introduction to iOS application development. It discusses what iOS is, the requirements to develop iOS apps including having a Mac, Xcode, and the iOS SDK. It then explains Objective-C, the programming language used to develop iOS apps, covering classes, instances, methods, properties, protocols, and categories. It provides examples of how to declare and define classes, create instances, and define methods and properties in Objective-C.
The document provides an overview of Objective-C basics including the Objective-C language, build and runtime, classes, objects, methods, and data encapsulation. It discusses the three main parts of an Objective-C class which are the @interface section for declarations, the @implementation section for definitions, and the program section for problem solving code. Methods are explained as actions performed on class instances that can affect the object's state. The document also covers how to create objects from classes, access methods, and encapsulate data to hide instance variables from direct access.
Objective-C is an object-oriented programming language that adds Smalltalk-style messaging to C. It allows programmers to define classes and objects that send and receive messages. Key features include classes and objects, memory management through retain counts, categories to add methods to classes, and protocols to define method requirements. Objective-C code uses square brackets [] to send messages between objects and uses dot syntax as a shorthand. Recommended resources for learning more about Objective-C include Apple's documentation and books focused on Cocoa and Objective-C.
Objective-C began as an extension of C created by Brad Cox and Tom Love to make C more object-oriented like Smalltalk. It was later acquired and further developed by NeXT and then Apple. Objective-C adds object-oriented capabilities and messaging to C by allowing classes and methods. It uses dynamic typing where actions can be taken at runtime. Objective-C became widely used with Apple's development of Cocoa and Cocoa Touch frameworks, which use Objective-C for building iOS and macOS applications in an object-oriented way.
This document provides an introduction to Objective-C, including:
- Objective-C is a programming language used by Apple for iOS and Mac apps that is a superset of C and adds object-oriented capabilities.
- The language consists of objects, classes, methods, and messages that allow objects to communicate with each other.
- Keywords like @interface, @implementation, and @protocol are used to define classes, categories, and protocols.
- The document discusses features like properties, memory management, and differences between instance and class methods.
Este documento resume los aspectos fiscales para desarrolladores de aplicaciones en España. Explica que los desarrolladores deben firmar un contrato con Apple y están sujetos a las leyes fiscales españolas sobre los ingresos obtenidos a través de la App Store. También resume los impuestos principales en España, como el IRPF e IVA, y las opciones para registrarse como autónomo o constituir una sociedad. Además, resume las nuevas leyes que ofrecen incentivos fiscales y de seguridad social para emprendedores en España.
Este documento resume las principales consideraciones fiscales para los desarrolladores de aplicaciones en España. Explica que los desarrolladores deben firmar un contrato individual con Apple y están sujetos a las leyes fiscales españolas sobre sus ingresos procedentes del extranjero. También describe los impuestos principales a los que están sujetos los autónomos en España, como el IRPF e IVA, y las opciones para pagar cuotas reducidas de la Seguridad Social. Además, analiza algunas ventajas de constituir una empresa en el Reino Unido o
The document discusses the Multipeer Connectivity framework in iOS, which allows discovering and communicating with nearby iOS devices using WiFi and Bluetooth. It describes classes for creating peer identities (MCPeerID), advertising and browsing for services (MCAdvertiserAssistant, MCBrowserViewController, MCNearbyServiceBrowser), managing communication sessions (MCSession), and sending data, streams, and resources between peers. The framework supports both reliable and unreliable data transfer, with options for more customization.
El documento presenta una introducción al desarrollo guiado por pruebas (TDD) en 3 partes. La primera parte explica la secuencia de trabajo de TDD, los beneficios y desafíos. La segunda parte describe las pruebas de la interfaz de usuario de una aplicación de muestras. La tercera parte presenta un método para probar y refactorizar código de otros desarrolladores.
The document discusses various techniques for animating views and constraints in Auto Layout, including:
- Animating a constraint's constant property and calling layoutIfNeeded in the animation block
- Animating layers instead of views for smoother animations
- Dropping constraints temporarily and using autosizing masks for animation
- Using a container view to help manage animations
Este documento presenta varias opciones para el reporte de crashes en iOS como iTunes Connect, BugSense, Crittercism, HockeyApp, Flurry, TestFlight y Crashlytics. Se enfoca en Crashlytics debido a que provee informes completos y análisis en tiempo real del crash, información detallada del dispositivo, integración con herramientas de gestión de bugs, interfaz de usuario y soporte al cliente. Crashlytics también permite logging personalizado, añadir información del usuario a los informes y genera informes diarios y de crashes cer
Este documento ofrece una guía sobre los costos típicos de desarrollar una aplicación móvil. Explica que el precio depende de factores como el alcance de la funcionalidad, si es una app nativa o basada en web, si requiere conectividad con un servidor, el diseño, testing, soporte, marketing y más. Provee algunos rangos de precios como $1,500 para una app básica sin código, $10,000-$90,000 para una app mediana con testing y soporte, y $100,000-$300,000 para
El documento habla sobre la accesibilidad de las aplicaciones para iPhone. Explica que la mayoría de las aplicaciones serán accesibles sin modificar código (80%), pero se puede mejorar hasta el 95% realizando pequeños cambios en Interface Builder. Para lograr el 100% de accesibilidad, es necesario implementar métodos de accesibilidad mediante código.
Este documento introduce la biblioteca CorePlot, la cual permite agregar gráficos interactivos a aplicaciones como líneas, dispersión, barras y circulares. Explica cómo importar CorePlot a un proyecto, incluyendo la creación de un grupo para las librerías externas y agregar las dependencias y enlaces binarios requeridos. Además, presenta los conceptos básicos detrás de los gráficos de CorePlot como el CPTGraphHostingView, CPTGraph y diferentes tipos de plots.
5. Objective-C is object oriented and
objects are
C structs
@interface Person @end
@implementation Person @end
6. Objective-C is object oriented and
objects are
C structs
@interface Person @end
@implementation Person @end
struct Person {
Class isa;
}
7. Objective-C is object oriented and
objects are
C structs
@interface Person @end
@implementation Person @end
struct Person {
Class isa;
}
struct objc_class {
Class isa;
Class super_class
char *name
long version
long info
long instance_size
objc_ivar_list *ivars
objc_method_list **methodLists
objc_cache *cache
objc_protocol_list *protocols
}
8. Objective-C is object oriented and
objects are reflection
C structs
@interface Person @end
@implementation Person @end
struct Person {
Class isa;
}
struct objc_class {
Class isa;
Class super_class
char *name
long version
long info
long instance_size
objc_ivar_list *ivars
objc_method_list **methodLists
objc_cache *cache
objc_protocol_list *protocols
}
9. Objective-C is object oriented and
objects are reflection
C structs
[NSString alloc]
@interface Person @end
@implementation Person @end
struct Person {
Class isa;
}
struct objc_class {
Class isa;
Class super_class
char *name
long version
long info
long instance_size
objc_ivar_list *ivars
objc_method_list **methodLists
objc_cache *cache
objc_protocol_list *protocols
}
10. Objective-C is object oriented and
objects are reflection
C structs
[NSString alloc]
@interface Person @end
@implementation Person @end objc_msgSend(objc_getClass("NSString"),
sel_registerName("alloc"))
struct Person {
Class isa;
}
struct objc_class {
Class isa;
Class super_class
char *name
long version
long info
long instance_size
objc_ivar_list *ivars
objc_method_list **methodLists
objc_cache *cache
objc_protocol_list *protocols
}
11. Objective-C is object oriented and
objects are reflection
C structs
[NSString alloc]
@interface Person @end
@implementation Person @end objc_msgSend(objc_getClass("NSString"),
sel_registerName("alloc"))
struct Person {
Class isa; alloc 0x00002710
}
struct objc_class {
Class isa;
Class super_class
char *name
long version
long info
long instance_size
objc_ivar_list *ivars
objc_method_list **methodLists
objc_cache *cache
objc_protocol_list *protocols
}
12. Objective-C is object oriented and
objects are reflection
C structs
[NSString alloc]
@interface Person @end
@implementation Person @end objc_msgSend(objc_getClass("NSString"),
sel_registerName("alloc"))
struct Person {
Class isa; alloc 0x00002710
}
“Objective-c has
struct objc_class {
Class isa;
Class super_class
char *name
long version message passing,
long info
long instance_size
objc_ivar_list *ivars
objc_method_list **methodLists
objc_cache *cache
objc_protocol_list *protocols
}
#4: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#5: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#6: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#7: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#8: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#9: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#10: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#11: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#12: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#13: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#14: \nThe runtime is a library that implements Objective-C on top of C.\n\nObjective-C is dynamic and object oriented. Both properties are implemented in the runtime.\n\nObjective-C is object oriented because it has objects. Those objects are written in Objective-C and translated to C functions and structs by the compiler.\n\nObjective-C is dynamic because it has features that other languages only have during compile time, like reflection. \nReflection is the ability to observe and alter its own state. In other words, “the ability of introspect and intervene on reified language elements during execution”.\n\nTo accomplish reflection, all elements of an Objective-C program, like objects, methods, properties, categories, protocols, etc. are represented by C structs defined in the runtime. It also provides functions to observe and change these elements during run time.\n\nIf you look at a language like C, calls to C functions are replaced with a jump to the address of that function implementation. Dynamic languages don’t work that way. There is a mechanism embedded with your program (the runtime) that decides what implementation to run for each method. This information is kept on a “virtual table” that may be array (C++) or hash based (Objective-C). This makes manipulation much easier.\n\nMethod or functions calls are translated by the compiler as a jump to a fixed point in code. A message send however, requires a decision in runtime to associate the message with its implementation.\n\nThe phrase “Objective-C has message passing, not method calls” is related to this. In Objective-C you don’t jump to the implementation directly, you pass a message saying you want to execute a method, and the runtime decides what implementation to run in response. If later you want to change the implementation of a method, you do it on the virtual table (for example, loading a category).\n\nLet’s say what is a message and what is a method call... [next slide]\n\n
#15: \nA message is an invocation of the method. A function call is a jump to an implementation address. \n\nThe difference is that a message requires a decision in run time to associate the message with its implementation. One happens at run time, the other at compile time.\n\nFor example, let’s say I send the message [NSString randomStringWithLength:10]. That’s not a method of the class NSString, unless I add it during run time.\nHow do I do that? I can use a category, load a module using the runtime (objc_loadModules) or NSBundle, or create the code. All these actions change a pair (method name, implementation address) on a method hash table of the object.\n\n*A module is the minimum independent compilable unit of code. A m file generates one module per object.\n\nSo, the compiler uses the data structures and function calls of the runtime to generate a runtime layer for every Objective-C program created. This means that the runtime library (/usr/lib/libobjc.A.dylib) is linked on all programs, and is therefore, available to use in your own code. \nApple’s runtime is mostly written in C, with pieces in C++ and assembler.\n\n
#16: \nEvery solution is one indirection away. These are some features that depend on method and ivar indirection.\n\nIntrospection. The ability to inspect the properties and methods of a class.\nLate method binding. The implementation of a message is decided during runtime by the object that receives the message.\n\nClass and method creation and swizzling. Replacement and creation of existing code, eg: KVO, auto synthesize, @dynamic.\nForwarding proxy support. The ability for a class to work as proxy of another. This can be used to mimic multiple inheritance.\nCategories. Adds methods to an existing class at runtime without recompiling.\nNon-fragile instance variables. The ability of compiled code to work with new superclasses that have more instance variables than they had when the code was compiled. eg: auto synthesize.\n
#17: \nA class is fragile when any change requires recompilation of all its subclasses. Even if the change was just adding private methods or variables, binary compatibility is lost.\n\nObjective-C always had non-fragile methods due to dynamic dispatch. Objective-C 2.0 added a layer of indirection in variables that lets the dynamic linker adjust instance layout at runtime.\nIn this image, the runtime detects a new version of the base class and increases the offset of the existing ivars to accommodate the new ivars of the base class.\n\nNon-fragile instance variables allows the following improvements:\nivar autosynthesis. This is the runtime creation of property ivars not declared in the class interface.\nivars declared outside a class's interface. \n
#18: \n@dynamic means: don’t auto synthesize the accessors, I’ll provide the code myself.\nCore Data uses this in managed objects to generate the accessors during runtime.\n
#19: Let’s say we have this Person class with a name property and a mutable dictionary.\nWe are going to generate accessors to store the property in the dictionary, instead of using the property.\nLet’s imagine that this is Core Data and that dictionary is sqlite :P\n
#20: \nAnd this is how we create the dynamic accessors for any property at all.\nAlso, an example use of resolveInstanceMethod:.\n\n(explain the code)\n\ntype encoding is return type, id, self, arguments\n
#21: \nSwizzling is the replacing of methods of classes in an instance.\nWhen you replace a method the cache is also filled with it.\n\nWhen we add KVO to a class: \n Apple code creates a subclass that overrides methods with versions that send -willChangeValueForKey: and -didChangeValueForKey: to any registered observer before and after calling the original class methods.\n The isa pointer of the original class is replaced with this new subclass.\n When all the observers are removed, the original class is swizzled back.\n\nThe subclass replaces the class method to try to hide its existence. Example:\n[person class]; // Person\nobject_getClass(person)); // NSKVONotifying_Person\n\n\n-- SWIZZLING STUFF BUT NOT MUCH TALKING ABOUT THE RUNTIME --\n\nWhy not a category?\n\n If you use a category and the method is overridden in another category, it’s undefined which implementation wins. \n If you use a category, the original implementation is lost.\n\nMethod Swizzling\n\n Impacts every instance of the class\n Highly transparent. All objects retain their class.\n Requires unusual implementations of override methods, like C functions with self and _cmd as parameters. Or you can use method_exchangeImplementations instead C function pointers. \n The swizzling fills the cache.\n\nISA Swizzling\n\n Only impacts the targeted instance\n Objects change class (though this can be hidden by overriding class)\n Override methods are written with standard subclass techniques \n\nProblems with Swizzling\n\n Method swizzling is not atomic. Do it in +load if you can to avoid concurrency issues. \n Changes behavior of un-owned code. App may be rejected if you swizzle Apple’s API.\n Possible naming conflicts. You can use function pointers directly to avoid this. See Dangers of swizzling.\n Swizzling changes the method's arguments\n The order of swizzles matters. Use +load so there is an order: superclass first.\n Difficult to understand (may look recursive)\n Difficult to debug \n\nPractical uses for swizzling\n Implement KVO.\n Automatically removing KVO notifications at object deallocation\n Run once some slow method and replace it with a faster one.\n\nSee https://github.com/rentzsch/jrswizzle for a swizzle implementation.\n\n\n\n
#22: \nThe KVO code is not public, but we can imagine that the subclass is created dynamically like we see here. \n\n(explain the code)\n\nthe kvoProperty could be a generic method that finds out the property name from the _cmd, I don’t know, maybe the GNUStep project has an example\n\n
#23: \nOnce created we replace the isa pointer.\n\nBe careful not to add instance variables or the increased size will overwrite memory crashing the app!\n\n
#24: NeXT. Never released. Superseded by Apple.\nApple's Legacy runtime. An improved version of the NeXT Objective-C runtime. Open source but not portable outside Darwin.\nApple's Objective-C 2.1. Open source.\nÉtoilé Runtime. A research prototype merged with GNUStep.\nGNUStep\nGNUStep is a GNU implementation of the Objective-C runtime and Cocoa.\nThe license is GPL for applications, and LGPL for libraries.\nIt is available as binary in macports, or source in svn, mirrored in github/gnustep.\nNSObject is in NSObject.m (svn), or NSObject.m (github). \n\nApple’s runtime is open source: http://www.opensource.apple.com/source/objc4/\n
#27: Objective-C is mostly C and objects. \n\nObjects respond to messages, can be queried at runtime without knowing their exact type, placed in collections, compared for equality, and share a common set of behavior. \n\nBecause Class is a struct with a pointer to its metaclass, it is an object too. \n\nThe missing piece is objc_class...\n
#28: We notice two things:\n\n The contents are deprecated in Objective-C 2.0.\n It points to another Class, commonly referred as "metaclass". \n\nBefore Objective-C 2.0 all Objective-C objects were instances of the C struct objc_object. Now the type is opaque and this struct is marked deprecated. You can still access the fields using C functions, but not reference them directly. This gives Apple engineers more liberty to change the layout of the struct without breaking compatibility. The struct is still worth a look because the current version is probably very similar.\n\nBecause the first field is an isa, message sending works just as with NSObject. So a Class is an object too, and we can send it messages with selectors of class methods. The following is equivalent:\n\n [NSObject alloc]\n [[NSObject class] alloc]\n\nJust as this objc_method_list of the current class points to the instance methods, the objc_method_list of the metaclass points to the class methods. The metaclass isa just points to itself.\n\nYou can use the debugger to create an object and then do p *object. You will see a struct with a field Class isa, but since the type is opaque, there are no more fields to print than isa. We have to use functions of the runtime. \n\n-- SKIP, XCODE EXAMPLE --\n\nexpr (long)class_getInstanceSize((Class)[o class])\np (int)class_getVersion((Class)[o class])\n\nIf that syntax seems foreign to you, read the LLDB tutorial.\n\nThe class describes the data (allocation size, ivar types, layout) and behaviour (methods it implements). Because there is only one isa pointer, there is no multiple inheritance. \n\n
#29: \nRead only.\n\nivars are in the read only section. Categories can’t change them.\n
#30: \nRead/write.\n\nfirstSubclass and nextSiblingClass point to the subclasses of the class. They can’t be used because access to them use a lock which is not accessible outside the runtime library. Without using that lock you could crash if another thread is reading them.\n\n
#33: \nA root object. Since it doesn’t inherit new, I’m creating one. I’m using createInstance, which internally does a calloc of the struct and assigns the class. You can look at it in the Object.m, which suports the legacy runtime. The modern runtime version is probably very similar.\n\nWe can rewrite this objective-c to C++ using “clang -rewrite-objc main.m”. The answer will be mostly C.\n\n
#34: The new method is now a C function.\n\nThe call to the C function is made with an objc_msgSend function call. This function is written in assembler in file objc-msg-x86_64.s of the runtime, and chooses the implementation of the messages we send.\n\nThe objc_method is the definition of Method. It has a name, pointer to implementation, and a string describing the return and parameter types. The format is in “Objective-C Runtime Guide: Type Encodings”.\n
#35: At the top there is a class method initialization.\n\nThen we have the class definition, and the initialization of the class and metaclass. Some values are 0 because they are initialized at run time. The metaclass is the class of the class. The same structure is used, but the metaclass is used to store class methods.\n\n
#36: A module is the smallest unit of code and data that can be linked. A objc_module structure is created for each .m file with an object declaration. _symtab contains the number of classes and categories declared in the module. \n\nThe __OBJC means this is a segment with information for the Objective-C runtime library.\n\n\n
#37: clang -lobjc main.m\notool -L a.out\notool -L /usr/lib/libobjc.A.dylib\notool -L /usr/lib/libSystem.B.dylib\nnm a.out\nclass-dump a.out\n\nThere is more info on this in the Mach-O documentation. Mach-O is ABI (application binary interface) for OS X. It’s the equivalent of ELF in Linux or PE in Windows. In other words, the Mach-O defines the structure of an executable, where is the data, the executable code, the architecture, etc. \n\nYou can use otool or the “MachOViewer” (a 3rd party app) to see the structure of an executable.\n\nIf we do “otool -L a.out” we get the linked libraries. We can repeat on the libraries to see their dependencies. [CLICK] [CLICK]\nUse “nm a.out” to print the symbol table.\n\nThe registers used indicate the architecture. [CLICK]\n\nThis one is Hopper [CLICK]. It’s 29€. If you don´t want to spend the money, there is a command line tool called “otx” which also produces annotated assembler.\n\n\n\n
#38: clang -lobjc main.m\notool -L a.out\notool -L /usr/lib/libobjc.A.dylib\notool -L /usr/lib/libSystem.B.dylib\nnm a.out\nclass-dump a.out\n\nThere is more info on this in the Mach-O documentation. Mach-O is ABI (application binary interface) for OS X. It’s the equivalent of ELF in Linux or PE in Windows. In other words, the Mach-O defines the structure of an executable, where is the data, the executable code, the architecture, etc. \n\nYou can use otool or the “MachOViewer” (a 3rd party app) to see the structure of an executable.\n\nIf we do “otool -L a.out” we get the linked libraries. We can repeat on the libraries to see their dependencies. [CLICK] [CLICK]\nUse “nm a.out” to print the symbol table.\n\nThe registers used indicate the architecture. [CLICK]\n\nThis one is Hopper [CLICK]. It’s 29€. If you don´t want to spend the money, there is a command line tool called “otx” which also produces annotated assembler.\n\n\n\n
#39: clang -lobjc main.m\notool -L a.out\notool -L /usr/lib/libobjc.A.dylib\notool -L /usr/lib/libSystem.B.dylib\nnm a.out\nclass-dump a.out\n\nThere is more info on this in the Mach-O documentation. Mach-O is ABI (application binary interface) for OS X. It’s the equivalent of ELF in Linux or PE in Windows. In other words, the Mach-O defines the structure of an executable, where is the data, the executable code, the architecture, etc. \n\nYou can use otool or the “MachOViewer” (a 3rd party app) to see the structure of an executable.\n\nIf we do “otool -L a.out” we get the linked libraries. We can repeat on the libraries to see their dependencies. [CLICK] [CLICK]\nUse “nm a.out” to print the symbol table.\n\nThe registers used indicate the architecture. [CLICK]\n\nThis one is Hopper [CLICK]. It’s 29€. If you don´t want to spend the money, there is a command line tool called “otx” which also produces annotated assembler.\n\n\n\n
#40: clang -lobjc main.m\notool -L a.out\notool -L /usr/lib/libobjc.A.dylib\notool -L /usr/lib/libSystem.B.dylib\nnm a.out\nclass-dump a.out\n\nThere is more info on this in the Mach-O documentation. Mach-O is ABI (application binary interface) for OS X. It’s the equivalent of ELF in Linux or PE in Windows. In other words, the Mach-O defines the structure of an executable, where is the data, the executable code, the architecture, etc. \n\nYou can use otool or the “MachOViewer” (a 3rd party app) to see the structure of an executable.\n\nIf we do “otool -L a.out” we get the linked libraries. We can repeat on the libraries to see their dependencies. [CLICK] [CLICK]\nUse “nm a.out” to print the symbol table.\n\nThe registers used indicate the architecture. [CLICK]\n\nThis one is Hopper [CLICK]. It’s 29€. If you don´t want to spend the money, there is a command line tool called “otx” which also produces annotated assembler.\n\n\n\n
#41: clang -lobjc main.m\notool -L a.out\notool -L /usr/lib/libobjc.A.dylib\notool -L /usr/lib/libSystem.B.dylib\nnm a.out\nclass-dump a.out\n\nThere is more info on this in the Mach-O documentation. Mach-O is ABI (application binary interface) for OS X. It’s the equivalent of ELF in Linux or PE in Windows. In other words, the Mach-O defines the structure of an executable, where is the data, the executable code, the architecture, etc. \n\nYou can use otool or the “MachOViewer” (a 3rd party app) to see the structure of an executable.\n\nIf we do “otool -L a.out” we get the linked libraries. We can repeat on the libraries to see their dependencies. [CLICK] [CLICK]\nUse “nm a.out” to print the symbol table.\n\nThe registers used indicate the architecture. [CLICK]\n\nThis one is Hopper [CLICK]. It’s 29€. If you don´t want to spend the money, there is a command line tool called “otx” which also produces annotated assembler.\n\n\n\n
#42: clang -lobjc main.m\notool -L a.out\notool -L /usr/lib/libobjc.A.dylib\notool -L /usr/lib/libSystem.B.dylib\nnm a.out\nclass-dump a.out\n\nThere is more info on this in the Mach-O documentation. Mach-O is ABI (application binary interface) for OS X. It’s the equivalent of ELF in Linux or PE in Windows. In other words, the Mach-O defines the structure of an executable, where is the data, the executable code, the architecture, etc. \n\nYou can use otool or the “MachOViewer” (a 3rd party app) to see the structure of an executable.\n\nIf we do “otool -L a.out” we get the linked libraries. We can repeat on the libraries to see their dependencies. [CLICK] [CLICK]\nUse “nm a.out” to print the symbol table.\n\nThe registers used indicate the architecture. [CLICK]\n\nThis one is Hopper [CLICK]. It’s 29€. If you don´t want to spend the money, there is a command line tool called “otx” which also produces annotated assembler.\n\n\n\n
#43: clang -lobjc main.m\notool -L a.out\notool -L /usr/lib/libobjc.A.dylib\notool -L /usr/lib/libSystem.B.dylib\nnm a.out\nclass-dump a.out\n\nThere is more info on this in the Mach-O documentation. Mach-O is ABI (application binary interface) for OS X. It’s the equivalent of ELF in Linux or PE in Windows. In other words, the Mach-O defines the structure of an executable, where is the data, the executable code, the architecture, etc. \n\nYou can use otool or the “MachOViewer” (a 3rd party app) to see the structure of an executable.\n\nIf we do “otool -L a.out” we get the linked libraries. We can repeat on the libraries to see their dependencies. [CLICK] [CLICK]\nUse “nm a.out” to print the symbol table.\n\nThe registers used indicate the architecture. [CLICK]\n\nThis one is Hopper [CLICK]. It’s 29€. If you don´t want to spend the money, there is a command line tool called “otx” which also produces annotated assembler.\n\n\n\n
#44: clang -lobjc main.m\notool -L a.out\notool -L /usr/lib/libobjc.A.dylib\notool -L /usr/lib/libSystem.B.dylib\nnm a.out\nclass-dump a.out\n\nThere is more info on this in the Mach-O documentation. Mach-O is ABI (application binary interface) for OS X. It’s the equivalent of ELF in Linux or PE in Windows. In other words, the Mach-O defines the structure of an executable, where is the data, the executable code, the architecture, etc. \n\nYou can use otool or the “MachOViewer” (a 3rd party app) to see the structure of an executable.\n\nIf we do “otool -L a.out” we get the linked libraries. We can repeat on the libraries to see their dependencies. [CLICK] [CLICK]\nUse “nm a.out” to print the symbol table.\n\nThe registers used indicate the architecture. [CLICK]\n\nThis one is Hopper [CLICK]. It’s 29€. If you don´t want to spend the money, there is a command line tool called “otx” which also produces annotated assembler.\n\n\n\n
#45: \nSmallTalk Issue Of Byte, Volume 6, Number 8, August 1981 \n\nBrad Cox and Tom Love created Objective-C because they needed object orientation. At the time they were trying to figure out which language to use for international teams building telephone switches. Brad had read an article about Smalltalk on the Byte magazine, and thought he could implement the same features in C without much fuss. Not that he had a lot of choices. The popular languages were Ada, Pascal, COBOL, FORTRAN, C, Lisp, and Smalltalk. Because Xerox wouldn’t sell Smalltalk, they built their own language on top of C. \n\nThe first Objective-C compiler was really a preprocessor translating objc to C.\n
#47: Every Objective-C method is translated to an msgSend function. The function is automatically given 2 arguments with the receiver and the name of the method. The rest are the arguments of the original method.\n\nDepending on the receiver (super, other) and the value returned (simple, struct, float), there are several versions of this function.\n\nThis function call is usually generated by the compiler. If you write it by hand, you have to choose the correct version:\nobjc_msgSend. Used when a simple value is returned.\nobjc_msgSend_fpret. Only used when a float is returned and the processor is Intel.\nobjc_msgSend_stret. Used when a struct is returned.\nobjc_msgSendSuper. Used when a simple value is returned and the message is sent to the superclass.\nobjc_msgSendSuper_stret. Used when super returns a struct and the message is sent to the superclass. \n\nApple´s implementation is in objc4-532/runtime/Messengers.subproj/objc-msg-x86_64.s It´s written in assembly.\n
#48: \nEach instance has a pointer to its class (the isa pointer).\nEach class has pointers to its superclass and metaclass.\nEach metaclass has a pointer to its meta superclass. \n\nThe class structure is the same for class and meta class, but some pointers are unused:\n A metaclass doesn´t have a meta meta class so the pointer points to the root meta class.\n A root meta class doesn´t have a meta superclass so the pointer points to its class.\n A root class doesn´t have a superclass so the pointer points to nil.\n\n
#49: \nIf GC is on, and the selector is retain, release, autorelease, or retainCount, ignore it and just return self.\n\nIf the receiver is nil return nil or 0 or 0.0 or {0} depending on the return type. See 1, 2. Why not throw an exception instead? it makes the language more elegant. Consider [[[somePerson office] telephone] lastNumberDialed] as the same with ifs on each step.\n\nIf the selector is in the cache, call it. This is called the "fast path". It is implemented in the function IMP _class_lookupMethodAndLoadCache(Class cls, SEL sel) of objc-class.m. There is a cache per class. The cache contains all the methods of the class and its superclasses. Caches are filled as the methods are called.\n\nNote: The objc_sendMsg call always uses tail call elimination so it doesn’t show in the stack if you pause execution. This implies that you can’t know the caller in an optimized program.\n\nNote: Every time the runtime is looking for a selector, it uses pointer comparison, not string comparison. To accomplish this, all selectors of a process are uniqued. When you install OS X and you see at the end optimizing system, it is “uniquing” the framework selectors. That the selector is unique also produces a fast and stable (in time) search.\n\nNote: A selector is the same for all methods that have the same name and parameters — regardless of which objects define them, whether those objects are related in the class hierarchy, or actually have nothing to do with each other. \n\nIf the selector is in the class, add it to the cache and call it. This is called the "slow path". The slow path happens only the first time we call this selector. However, a swizzle or category load will flush the cache of the class.\nIf everything fails, follow the pointer to the superclass and repeat.\n\nIf you reach NSObject, the runtime calls the following methods:\n\n Call resolveInstanceMethod: or resolveClassMethod:. If they return YES, go back to the slow path step. \n (these methods provide the chance to add a method dynamically using runtime functions)\n\n Call forwardingTargetForSelector:. If it returns an object, repeat on the given object.\n (this method provides a chance to mimic multiple inheritance).\n\n Call methodSignatureForSelector:. If it returns a method signature, wrap it on a NSInvocation and call forwardInvocation:. The forwardInvocation: inherited from NSObject calls doesNotRecognizeSelector:, which throws an exception. \n\n\n\n\n
#50: \nIn C there is no indirection (aka no “virtual call”), so it’s always the fastest. \n\nC++ uses a “virtual table” per class, which is an array based structure. This structure is initialized in the constructor and doesn’t change during execution. There are no standards on the internal implementation of virtual tables, but all compilers do it that way. Because C++ has multiple inheritance there may be more one virtual table per base class.\nThe C++ compiler may create non virtual calls for some cases.\n\nObjective-C uses a hash table to store pairs of selector/IMP. But once a method is resolved an entry is added to a per class cache, which makes the call only slighter slower than a C++ or C call. This is because Objective-C has duck typing so there isn’t a known set of methods in advance to create an array with, and also because we can alter the caches loading categories or using the runtime. So instead an array, duck typed languages use hash tables with string keys.\n\nBecause the keys have to be unique, the selectors have to be unique for each class, and there can’t be polymorphism. \n\nFor OS X frameworks, caches are created in advance. It’s the “optimizing the system” at the end of OS X installation.\n\nObjective-C 2.1 (64-bit Mac OS X 10.6+) keeps a "virtual table" with 16 selectors most used everywhere and rarely overridden. These selectors make for 30%-50% of the selector calls in any application. Calls to those selectors are replaced at runtime with objc_msgSend_vtable functions. There are 16 functions.\n\nBecause Objective-C methods are C functions underneath, it's also possible to skip the messaging system and call the implementation directly, but it's an unusual optimization that saves little compared to a cached method call.\n
#51: Calling a method means running the C function behind every Objective-C method, and pass the arguments plus 2 more: self (the receiver) and _cmd (the method). Both _self and _cmd are available to use on every method.\n\nIn Objective-C you can also get the address of a method and call it directly without objc_msgSend.\n\nOnce resolved, we could store the method implementation on a pointer, and use it to perform function calls skipping the dispatch table. This is an optimization we can apply to methods that are run many times. In fact, the compiler generates an equivalent function call.\n\nThis saves little because once resolved, methods are cached in the objc_cache struct. So only the cache look-up is skipped.\n\nNote that the first arguments are id and SEL as told in the documentation for IMP. \n
#53: \nA x86 64 pointer has 64 bits, but only uses 48 bits for the pointer address. The reason is that 48 bit provides a 256 TB address space, which is a lot. Using 64 bits would be wasteful because it would require more transistors in the CPU. So the potential address space is 64bit, but current CPUs are only able to use 48.\nBecause of this, the ending bits of a pointer are 0 because they are left unused.\n\nTagged pointers are pointers which contain data instead an address. Example, let’s say we want to store the integer 42 in a pointer. We could create a NSNumber and then point to it, or we could replace the address with a 42, in which case we can skip object creation. \n\nTo distinguish between a normal pointer to an object and a tagged pointer, we can use the bits at the end. \nOS X Lion has tagged pointers, and uses the last bits as seen in the image.\n\nThe tagged object class is integer, managed object, or date. The next 4 bits are for information about the object class.\nTo read the value of the tagged pointer, the value is shifted 8 bits to discard the meta information on the image.\nTo know what the class is for each tagged pointer, there is a table in the runtime that maps the 4 bits to a Class. This table is used by object_getClass(), which means that we shouldn’t access the isa pointer directly for NSNumbers, because it may not work if it is a tagged pointer.\n\nNot every NSNumber can be turned into a tagged pointer. In those cases, the real object is created.\n\nTagged pointers save memory and increase performance. \nTagged pointers can be turned off with a compiler switch\n\n\n--Talk about NSConstantString and compile time constants--\n\noh hi, a number literal: http://jens.ayton.se/blag/objc-constant-objects/\n\n\n--SKIP THIS IF THERE IS NO TIME--\n\nIn a 64 bit architecture, memory access happens in chunks of 8 bytes (64 bits), and each memory access starts at an address which is a multiple of that size.\n\nExample: let’s say we want to read a 64 bit pointer which is not aligned, that is, half of it is in one chunk and the other half in the next. We will need two read operations and another to put the two halves together. Another problem is that the read is not atomic, so we could be reading invalid state. \nThis is just an example to illustrate that data alignment is required for performance and atomic operations. Most likely the CPU will throw an exception if we attempt to do such a thing.\n\nThe alignment depends on the size of the data. For example, a char is 1 byte, so it will be 1 byte aligned. In a 64 bit architecture we would be able to store 8 chars in one chunk (8*8 = 64). \n\nIn reality, x86-32 ABI and x86-64 ABI require 16 byte alignment. Example: let’s say we need to allocate memory and we use malloc. Because malloc doesn’t know what we are going to store, it assumes the worst case scenario, which is we are going to use Intel SIMD instructions which require 16 byte alignment. \n\nSee http://stackoverflow.com/a/898760/412916\nSee http://www.ibm.com/developerworks/library/pa-dalign/\nSee http://stackoverflow.com/a/3903577/412916\n\n
#54: \nAt one point Apple was developing Carbon (a C API) and Cocoa (a pure Objective-C API).\nCore Foundation was a C API common to both of them. \n\nToll Free Bridging is a mechanism that makes some Core Foundation classes interchangeable with its Cocoa counterparts.\n\nExample, we can cast between NSString and CFStringRef as if they were the same class. Actually NSString is a “class cluster”, which means that the visible class (NSString) is an abstract class, abstract in the sense that you never get a NSString instance but a NSString subclass (even when you call it NSString).\n\nHow it works?\n Some CF/NS objects have the same memory layout. In this case NS methods use the CF implementation.\n Some CF/NS objects wrap each other methods in C and objective-c. That is, their code is split between the CF and NS counterparts. This is good because you get advantages from both the static nature of C and the dynamic nature of Objective-C. Every function that works with TFB objects need to check if the object is one kind or another. When the object is NS, the class pointer has an special value.\n\nToll free bridge exists, but programmers shouldn’t rely on it.\n\n
#56: \nThe Block Implementation Specification (http://clang.llvm.org/docs/Block-ABI-Apple.txt) describes how blocks are implemented at the runtime level.\nThe project is called libclosure, and it is open source: http://www.opensource.apple.com/source/libclosure/\nTo download tarballs: http://www.opensource.apple.com/release/mac-os-x-1068/\n\nThere are a couple more documents in the root of the libclosure directory. One called “Language Specification for Blocks” and the other is an outdated version of the Block-ABI.\n\n\nAs an overview, here is a block definition. \n\nThe isa pointer to an object. If the block doesn’t capture variables the block is NSConcreteGlobalBlock (or NSGlobalBlock for Core Foundation), which is, I think, a static implementation that doesn’t require memory management (which is implemented with copy_helper and dispose_helper functions defined below). \nOtherwise the block is created in the stack which means it doesn’t survive the scope in which it was declared. That scope is defined by braces ({}). It can be a method, or the braces of a loop inside the method or whatever. This is an optimization that assumes that the block won’t be needed outside its definition scope. If this is not the case, we have to “copy” the block, which puts the block in the heap.\n\nThe flags indicate which kind of block it is.\n\nreserved is used internally as a retain counter (I think). This flag may be always 1 for a global block, or change if it is a stack block and we “copy” the block. To indicate we shouldn’t rely on this field, the method “retainCount” always returns 1 for a block.\n\nThe invoke function calls the block implementation, which is a C function. First argument is this struct, and the next are the arguments for the block.\n\nThe descriptor has the size of the block, a reserved field which is maybe unused, I don’t know and the docs don’t explain either. Functions for memory management. The signature is (I think) the version of the Application Binary Interface. \n\nThe imported variables at the bottom are the variables captured by the block. This variables are a “const” copy made on the stack. If they are primitives they become immutable, and if they are objects, the pointer is immutable but the pointed object is not. \nIf you copy the block, the variables are copied (malloc’ed) in the heap. You can actually see the change of address for the variable if you print it. \nCalling “retain” on a block doesn’t make a copy on the heap, only “copy” does.\n\n\n