What is the M file format?
.m is a plain-text file format used for storing source code written in the Objective-C programming language. A closely related extension, .mm, supports Objective-C mixed with C++ (Objective-C++). .m files are commonly found on Mac or Windows machines used for developing macOS and iOS applications. Each .m implementation file pairs with a companion .h header of the same base name, which holds the class interface declarations.
Objective-C is a programming language that adds object-oriented capabilities to the C language. Objective-C uses the Cocoa and Cocoa Touch frameworks and is mainly used for writing apps for Apple devices. Unlike C++, Objective-C is a strict superset of ANSI C. An .m file typically begins with #import directives (e.g. #import <Foundation/Foundation.h>) and contains @implementation ... @end blocks defining a class's methods. Since 2011, Automatic Reference Counting (ARC) automates memory management, removing the need for manual retain and release calls. .m files are compiled by clang inside Xcode. Since Apple introduced Swift in 2014, Objective-C is no longer the default for new projects, but .m files remain widespread in legacy codebases and in mixed Swift/Objective-C work.
Security & safety
RISK: LOWA .m file is plain source code - it does nothing until compiled and run, so the file itself is low risk. The normal source-code cautions apply: read before you build, since compiling and executing unknown code can do anything the resulting program is allowed to do, and source from untrusted repositories may hide malicious logic. There is no macro or auto-execution mechanism in a .m file by merely opening it in an editor. (If the .m turns out to be MATLAB rather than Objective-C, the same advice holds - don't run untrusted scripts.)
Format details
in a nutshell- MATLAB script / function file (.m) - Plain-text MATLAB code - scripts and functions for MathWorks MATLAB/Octave; the most common .m file in scientific/engineering use, a different language entirely.
- Wolfram Mathematica package (.m) - A Wolfram Language package/source file (also seen as .wl) holding definitions, opened by Mathematica.
- Maple input/.m library file - Maple uses .m for its internal (often binary) library/save files and Maple input code.
Programs that open M files
Technical details
deep spec| File type | Plain-text source code (no binary component) |
| MIME type | text/x-objcsrc (also accepted as text/plain) |
| Character encoding | UTF-8 or ASCII-compatible; historically also Mac Roman or Latin-1 |
| File signature (magic bytes) | None - identified by .m extension only; plain text with no binary header |
| Typical file structure | #import directives followed by one or more @implementation ... @end blocks |
| Companion header file | .h file of the same base name holds the class interface (@interface ... @end) |
| Key syntax tokens | @implementation, @end, @property, @synthesize, #import, - (returnType)methodName |
| Compiler | clang (LLVM); historically gcc before Apple switched in 2012 |
| Memory management model | Manual Reference Counting (MRC) or Automatic Reference Counting (ARC, since Xcode 4.2 / 2011) |
| Associated frameworks | Cocoa (macOS), Cocoa Touch (iOS/iPadOS) |
| Typical file size | A few hundred bytes to several hundred KB of source text |
| Objective-C++ variant | .mm extension used when Objective-C code must interoperate with C++ |
| Associated platforms | macOS, iOS, iPadOS (primary); GNUstep enables use on Linux and Windows |
| IDE and build tooling | Apple Xcode (primary IDE); clang and xcodebuild also used from the command line |
| Released | Objective-C language 1984; .m as the standard implementation-file extension since the NeXTSTEP era (late 1980s) |
| Latest version | Objective-C 2.0 (2006, Mac OS X 10.5); language is stable, now largely supplanted by Swift |
| Open standard | Yes · royalty-free |
| Specification | developer.apple.com |
M conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about M files.